The Standard ML Basis Library

Arrays and vectors

The SML Basis Library defines both polymorphic and monomorphic arrays and vectors. Arrays are mutable sequences, while vectors are immutable. Both arrays and vectors are indexed from zero, and provide constant time access and update operations. The monomorphic types are expected to have more compact representations than the corresponding polymorphic types. For example, a BoolVector implementation might use one bit per element.

A number of the array and vector operations take an array or vector slice as an argument. A slice is specified as a triple of type (seq * int * int option), where seq is the sequence type (array or vector). The expression (seq, i, SOME n) specifies the elements in seq from position i to i + (n - 1) (inclusive). When NONE is supplied as the third argument, the length is taken to be |seq| - i (i.e., the rest of seq from position i on). A slice is said to be valid if

0 <= i <= i+n <= |seq|
where n is the length of the slice. Note that when the length is specified as NONE this requirement reduces to 0 <= i <= |seq|.
Implementation note:

Note that when NONE is used to specify the length, the number of range checks can be reduced.

The Vector structure

The MONO_VECTOR signature

The Array structure

The MONO_ARRAY signature

The Array2 structure

The MONO_ARRAY2 signature

[ INDEX | TOP | Parent | Root ]

Last Modified April 16, 1996
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies