The DynamicArrayFn functor provides dynamically sized monomorphic
arrays. Each array has an associated default value, which is
covers those elements that have not been explicitly initialized
(conceptually, one can view an array as having an infinite size).
Thus, reads from indices above the bound will return the default value.
The bound of an array is the highest index of an initialized
element (or ~1 if there are no initialized elements). The
defined range of the array are the elements in the positions
indexed from zero to the bound.
Synopsis
signature MONO_DYNAMIC_ARRAY
functor DynamicArrayFn (A : MONO_ARRAY) : MONO_DYNAMIC_ARRAY
Functor Argument Interface
A : MONO_ARRAY
Functor Argument Description
A : MONO_ARRAY-
A structure that implements the
MONO_ARRAYsignature from the SML Basis Library.
Interface
type elem
type array
val array : (int * elem) -> array
val subArray : array * int * int -> array
val fromList : elem list * elem -> array
val toList : array -> elem list
val tabulate: int * (int -> elem) * elem -> array
val default : array -> elem
val sub : array * int -> elem
val update : array * int * elem -> unit
val bound : array -> int
val truncate : array * int -> unit
Interface Description
type elem-
The type of array elements.
type array-
The type of dynamic arrays.
val array : (int * elem) -> array-
array (sz, dflt)returns a new array with bound~1and default valuedflt. Theszargument, which must be non-negative, is used as a hint of the potential range of indices. This function raises theSizeexception ifsz < 0. val subArray : array * int * int -> array-
subArray (arr, lo, hi)returns a new array with the same default asarr, and whose values in the range[0, hi-lo]are equal to the values inarrin the range[lo, hi]. This function raises theSizeexception iflo < 0orhi < lo-1. val fromList : elem list * elem -> array-
fromList (lst, dflt)returns a new array created from the elements oflstand with default valuedflt. The bound of the array will belength lst - 1. val toList : 'a array -> 'a list-
toList arrreturns a list of the array’s contents. The resulting list will have the array’s bound plus one elements. val tabulate: int * (int -> elem) * elem -> array-
tabulate (sz, init, dflt)returns a new array with the firstszelements initialized using the functioninitand the default valuedflt. This function raises theSizeexception ifsz < 0. val default : array -> elem-
default arrreturns the default value for the array. val sub : array * int -> elem-
sub (arr, ix)returns the value of the array at indexix. If that value has not been explicitly set, then it returns the array’s default value. This function raises theSubscriptexception ifix < 0. val update : array * int * elem -> unit-
update (arr, ix, v)sets the value at indexixof the array tov. Ifixis greater than the current bound of the array, then the bound is set toix. This function raises theSubscriptexception ifix < 0. val bound : array -> int-
bound arrreturns the current bound of the array, which is the highest index that has been explicitly set (e.g., byupdate). val truncate : array * int -> unit-
truncate (arr, sz)sets every entry with index greater or equal toszto the array’s default value.