## 8 Basis library

This section describes MLton's implementation of the Standard ML Basis Library, which by default MLton makes available to user programs. The latest version of the Basis Library specification is at `http://www.standardml.org/Basis/`. For a reverse chronological list of changes to the specification, see `http://www.standardml.org/Basis/history.html`. Since the specification does change, we place a snapshot at `http://www.mlton.org/basis/` at the time of each MLton public release. You can also obtain a complete and current list of what's available by using `mlton -show-basis`.
In summary, MLton implements all of the required portions of the Basis Library. MLton also implements many of the optional structures, as seen below.

### 8.1 Toplevel types and constructors

`eqtype 'a array
datatype bool = false | true
eqtype char
type exn
eqtype int
datatype 'a list = nil | :: of ('a * 'a list)
datatype 'a option = NONE | SOME of 'a
datatype order = EQUAL | GREATER | LESS
type real
datatype 'a ref = ref of 'a
eqtype string
type substring
eqtype unit
eqtype 'a vector
eqtype word
`

### 8.2 Top level exception constructors

`Bind`, `Chr`, `Div`, `Domain`, `Empty`, `Fail`, `Match`, `Option`, `Overflow`, `Size`, `Span`, `Subscript`.

### 8.3 Top level values

MLton does not implement the optional top level value `use: string -> unit`, which conflicts with whole-program compilation because it allows new code to be loaded dynamically. MLton implements all other top level values:
`!`, `*`, `+`, `-`, `/`, `:=`, `<`, `<=`, `<>`, `=`, `>`, `>=`, `@`, `^`, `~`. `abs`, `app`, `before`, `ceil`, `chr`, `concat`, `div`, `exnMessage`, `exnName`, `explode`, `floor`, `foldl`, `foldr`, `getOpt`, `hd`, `ignore`, `implode`, `isSome`, `length`, `map`, `mod`, `not`, `null`, `o`, `ord`, `print`, `real`, `rev`, `round`, `size`, `str`, `substring`, `tl`, `trunc`, `valOf`, `vector`.

### 8.4 Top level signatures

`ARRAY`
`ARRAY2`
`ARRAY_SLICE`
`BIN_IO`
`BIT_FLAGS`
`BOOL`
`BYTE`
`CHAR`
`COMMAND_LINE`
`DATE`
`GENERAL`
`GENERIC_SOCK`
`IEEE_REAL`
`IMPERATIVE_IO`
`INET_SOCK`
`INTEGER`
`INT_INF`
`IO`
`LIST`
`LIST_PAIR`
`MATH`
`MONO_ARRAY`
`MONO_ARRAY2`
`MONO_ARRAY_SLICE`
`MONO_VECTOR`
`MONO_VECTOR_SLICE`
`NET_HOST_DB`
`NET_PROT_DB`
`NET_SERV_DB`
`OPTION`
`OS`
`OS_FILE_SYS`
`OS_IO`
`OS_PATH`
`OS_PROCESS`
`PACK_REAL`
`PACK_WORD`
`POSIX`
`POSIX_ERROR`
`POSIX_FILE_SYS`
`POSIX_IO`
`POSIX_PROCESS`
`POSIX_PROC_ENV`
`POSIX_SIGNAL`
`POSIX_SYS_DB`
`POSIX_TTY`
`PRIM_IO`
`REAL`
`SOCKET`
`STREAM_IO`
`STRING`
`STRING_CVT`
`SUBSTRING`
`TEXT`
`TEXT_IO`
`TEXT_STREAM_IO`
`TIME`
`TIMER`
`UNIX`
`UNIX_SOCK`
`VECTOR`
`VECTOR_SLICE`
`WORD`.

### 8.5 Top level structures

`Array: ARRAY`
`Array2: ARRAY2`
`ArraySlice: ARRAY_SLICE`
`BinIO: BIN_IO`
`BinPrimIO: PRIM_IO`
`Bool: BOOL`
`BoolArray: MONO_ARRAY`
`BoolArray2: MONO_ARRAY2`
`BoolArraySlice: MONO_ARRAY_SLICE`
`BoolVector: MONO_VECTOR`
`BoolVectorSlice: MONO_VECTOR_SLICE`
`Byte: BYTE`
`Char: CHAR`
`CharArray: MONO_ARRAY`
`CharArray2: MONO_ARRAY2`
`CharArraySlice: MONO_ARRAY_SLICE`
`CharVector: MONO_VECTOR`
`CharVectorSlice: MONO_VECTOR_SLICE`
`CommandLine: COMMAND_LINE`
`Date: DATE`
`FixedInt: INTEGER`
`General: GENERAL`
`GenericSock: GENERIC_SOCK`
`IEEEReal: IEEE_REAL`
`INetSock: INET_SOCK`
`IO: IO`
`Int: INTEGER`
`IntArray: MONO_ARRAY`
`IntArray2: MONO_ARRAY2`
`IntArraySlice: MONO_ARRAY_SLICE`
`IntVector: MONO_VECTOR`
`IntVectorSlice: MONO_VECTOR_SLICE`
`Int8: INTEGER`
`Int8Array: MONO_ARRAY`
`Int8Array2: MONO_ARRAY2`
`Int8ArraySlice: MONO_ARRAY_SLICE`
`Int8Vector: MONO_VECTOR`
`Int8VectorSlice: MONO_VECTOR_SLICE`
`Int16: INTEGER`
`Int16Array: MONO_ARRAY`
`Int16Array2: MONO_ARRAY2`
`Int16ArraySlice: MONO_ARRAY_SLICE`
`Int16Vector: MONO_VECTOR`
`Int16VectorSlice: MONO_VECTOR_SLICE`
`Int32: INTEGER`
`Int32Array: MONO_ARRAY`
`Int32Array2: MONO_ARRAY2`
`Int32ArraySlice: MONO_ARRAY_SLICE`
`Int32Vector: MONO_VECTOR`
`Int32VectorSlice: MONO_VECTOR_SLICE`
`Int64: INTEGER`
`Int64Array: MONO_ARRAY`
`Int64Array2: MONO_ARRAY2`
`Int64ArraySlice: MONO_ARRAY_SLICE`
`Int64Vector: MONO_VECTOR`
`Int64VectorSlice: MONO_VECTOR_SLICE`
`IntInf: INT_INF`
`LargeInt: INTEGER`
`LargeIntArray: MONO_ARRAY`
`LargeIntArray2: MONO_ARRAY2`
`LargeIntArraySlice: MONO_ARRAY_SLICE`
`LargeIntVector: MONO_VECTOR`
`LargeIntVectorSlice: MONO_VECTOR_SLICE`
`LargeReal: REAL`
`LargeRealArray: MONO_ARRAY`
`LargeRealArray2: MONO_ARRAY2`
`LargeRealArraySlice: MONO_ARRAY_SLICE`
`LargeRealVector: MONO_VECTOR`
`LargeRealVectorSlice: MONO_VECTOR_SLICE`
`LargeWord: WORD`
`LargeWordArray: MONO_ARRAY`
`LargeWordArray2: MONO_ARRAY2`
`LargeWordArraySlice: MONO_ARRAY_SLICE`
`LargeWordVector: MONO_VECTOR`
`LargeWordVectorSlice: MONO_VECTOR_SLICE`
`List: LIST`
`ListPair: LIST_PAIR`
`Math: MATH`
`NetHostDB: NET_HOST_DB`
`NetProtDB: NET_PROT_DB`
`NetServDB: NET_SERV_DB`
`OS: OS`
`Option: OPTION`
`PackReal32Big: PACK_REAL`
`PackReal32Little: PACK_REAL`
`PackReal64Big: PACK_REAL`
`PackReal64Little: PACK_REAL`
`PackRealBig: PACK_REAL`
`PackRealLittle: PACK_REAL`
`PackWord32Big: PACK_WORD`
`PackWord32Little: PACK_WORD`
`Position: INTEGER`
`Posix: POSIX`
`Real: REAL`
`RealArray: MONO_ARRAY`
`RealArray2: MONO_ARRAY2`
`RealArraySlice: MONO_ARRAY_SLICE`
`RealVector: MONO_VECTOR`
`RealVectorSlice: MONO_VECTOR_SLICE`
`Real32: REAL`
`Real32Array: MONO_ARRAY`
`Real32Array2: MONO_ARRAY2`
`Real32ArraySlice: MONO_ARRAY_SLICE`
`Real32Vector: MONO_VECTOR`
`Real32VectorSlice: MONO_VECTOR_SLICE`
`Real64: REAL`
`Real64Array: MONO_ARRAY`
`Real64Array2: MONO_ARRAY2`
`Real64ArraySlice: MONO_ARRAY_SLICE`
`Real64Vector: MONO_VECTOR`
`Real64VectorSlice: MONO_VECTOR_SLICE`
`Socket: SOCKET`
`String: STRING`
`StringCvt: STRING_CVT`
`Substring: SUBSTRING`
`SysWord: WORD`
`Text: TEXT`
`TextIO: TEXT_IO`
`TextPrimIO: PRIM_IO`
`Time: TIME`
`Timer: TIMER`
`Unix: UNIX`
`UnixSock: UNIX_SOCK`
`Vector: VECTOR`
`VectorSlice: VECTOR_SLICE`
`Word: WORD`
`WordArray: MONO_ARRAY`
`WordArray2: MONO_ARRAY2`
`WordArraySlice: MONO_ARRAY_SLICE`
`WordVectorSlice: MONO_VECTOR_SLICE`
`WordVector: MONO_VECTOR`
`Word8: WORD`
`Word8Array: MONO_ARRAY`
`Word8Array2: MONO_ARRAY2`
`Word8ArraySlice: MONO_ARRAY_SLICE`
`Word8Vector: MONO_VECTOR`
`Word8VectorSlice: MONO_VECTOR_SLICE`
`Word16: WORD`
`Word16Array: MONO_ARRAY`
`Word16Array2: MONO_ARRAY2`
`Word16ArraySlice: MONO_ARRAY_SLICE`
`Word16Vector: MONO_VECTOR`
`Word16VectorSlice: MONO_VECTOR_SLICE`
`Word32: WORD`
`Word32Array: MONO_ARRAY`
`Word32Array2: MONO_ARRAY2`
`Word32ArraySlice: MONO_ARRAY_SLICE`
`Word32Vector: MONO_VECTOR`
`Word32VectorSlice: MONO_VECTOR_SLICE`
`Word64: WORD`
`Word64Array: MONO_ARRAY`
`Word64Array2: MONO_ARRAY2`
`Word64ArraySlice: MONO_ARRAY_SLICE`
`Word64Vector: MONO_VECTOR`
`Word64VectorSlice: MONO_VECTOR_SLICE`
The following types are equivalent.

`Int.int = Int32.int`
`Int64.int = FixedInt.int = Position.int`
`IntInf.int = LargeInt.int`
`Real.real = Real64.real = LargeReal.real`
`Word.word = Word32.word = SysWord.word`
`Word64.word = LargeWord.word`

The `Real`, `Real32`, and `Real64` modules are implemented using the `C` math library, so the SML functions will reflect the behavior of the underlying library function. We have made some effort to unify the differences between the math libraries on different platforms, and in particular to handle exceptional cases according to the basis library specification. However, there will be differences due to different numerical algorithms and cases we may have missed. Please submit a bug report if you encounter an error in the handling of an exceptional case.
On x86, real arithmetic is implemented internally using 80 bits of precision. Using higher precision for intermediate results in computations can lead to different results than if all the computation is done at 32 or 64 bits. If you require strict IEEE compliance, you can compile with `-ieee-fp true`, which will cause intermediate results to be stored after each operation. This may cause a substantial performance penalty.

### 8.6 Top level functors

`ImperativeIO`
`PrimIO`
`StreamIO`
MLton's `StreamIO` functor takes structures `ArraySlice` and `VectorSlice` in addition to the arguments specified in the basis library documentation.