Chapter 3. The Basis Library

Table of Contents
Preliminaries
General
Option
Bool
Text
Integers
Reals
Lists
Arrays and Vectors
The Portable I/O API
The Portable OS API
The POSIX API

The Basis library is the library of standard types, functions and modules that are built-in for the Standard ML language. There is a set of reference documentation in the form of HTML pages for the library. You can download this documentation from the SML/NJ home page[SML]. You will need a copy of this documentation to follow the programming examples in this book.

In this chapter I will give you a brief overview of the library and discuss in more detail some of the more obscure features of the library. At the time of writing this, a more detailed book on the library is still in preparation (by another author).

You should also have a copy of the source code of the SML/NJ compiler. The Appendix C describes how to download it. The compiler is itself written in SML. The only part you need to pay attention to is the boot/ directory. This contains the source code of the Basis library as well as the SML/NJ extensions. I find it very useful to consult this when the documentation is unclear.

Preliminaries

Start by reading the Introduction to the library in the Basis documentation all the way through. Then read the "SML'96 Changes" section. This documents changes to the language since some of the books and tutorials on SML were written. The most notable changes for system programming are the addition of:

The value polymorphism restriction is not something you will likely encounter. For the purposes of this book it mainly requires you to ensure that imperative variables using the ref type are restricted to contain a specific declared type.

The section on type abbreviations in signatures allows type declarations like the type Option in the section called Getopt with a Hash Table in Chapter 2. I won't pay any attention to opaque signature matching but you will see it in some of the library source where a signature is matched using ":>" instead of ":". The difference is that the opaque form ensures that a type can be exported from a module with absolutely no information about its implementation being available. Normally the compiler peeks inside modules and can recognise when different type names exported from different modules are the same type because they have the same representation inside the module.

The next section on the "Top Level Environment" lists all of the types and functions that are available directly without having to be qualified by a module name. The phrase "top level" refers to the level of the prompt you get when you start up the SML compiler. All of these top-level names are associated with one of the library modules and are documented in more detail there. This section just provides are reference for what names don't need module qualification. The overloading of operators and their precedence is also presented.