The Array structure defines polymorphic arrays, mutable sequences with
constant-time access and update.
Arrays have a special equality property: two arrays are equal if they
are the same array, i.e., created by the same call to a primitive
array constructor such as array, fromList, etc.; otherwise they are
not equal. This also holds for arrays of zero length. Thus, the type
ty array admits equality even if ty does not.
structure Array : ARRAY
signature ARRAY =
sigtype 'a array = 'a array
type 'a vector = 'a vector
valmaxLen : int
valarray : int * 'a -> 'a array
valfromList : '_a list -> '_a array
valtabulate : int * (int -> 'a) -> 'a array
vallength : 'a array -> int
valsub : 'a array * int -> 'a
valupdate : 'a array * int * 'a -> unit
valvector : 'a array -> 'a vector
valcopy : {src: 'a array, dst: 'a array, di: int} -> unit
valcopyVec : {src: 'a vector, dst: 'a array, di: int} -> unit
valappi : (int * 'a -> unit) -> 'a array -> unit
valapp : ('a -> unit) -> 'a array -> unit
valmodifyi : (int * 'a -> 'a) -> 'a array -> unit
valmodify : ('a -> 'a) -> 'a array -> unit
valfoldl : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
valfoldr : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
valfoldli : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b
valfoldri : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b
valfindi : (int * 'a -> bool) -> 'a array -> (int * 'a) option
valfind : ('a -> bool) -> 'a array -> 'a option
valexists : ('a -> bool) -> 'a array -> bool
valall : ('a -> bool) -> 'a array -> bool
valcollate : ('a * 'a -> order) -> 'a array * 'a array -> order
end
creates a new array from l. The length of the array is
length l and the i(th) element of the array is the i(th) element of
the the list. If the length of the list is greater than maxLen, then
the Size exception is raised.
creates an array of n elements, where the elements
are defined in order of increasing index by applying f to the
element's index. This is equivalent to the expression (fromList
(List.tabulate (n, f))). If n < 0 or maxLen < n, then the Size
exception is raised.
These functions copy the entire array or
vector src into the array dst, with the i(th) element in src, for 0 <=
i < |src|, being copied to position di + i in the destination
array. If di < 0 or if |dst| < di+|src|, then the Subscript exception
is raised. In copy, if dst and src are equal, we must have di = 0 to
avoid an exception, and copy is then the identity.
These apply the function f to the elements of the array
arr in order of increasing indices. The more general form appi
supplies f with the array index of the corresponding element.
These apply the function f to the elements of the array
arr in order of increasing indices, and replace each element with the
result. The more general modifyi supplies f with the array index of
the corresponding element. The expression modify f arr is equivalent
to modifyi (f o #2) arr.
These fold the function f over all the elements of
the array arr, using the value init as the initial value. The
functions foldli and foldl apply the function f from left to right
(increasing indices), while the functions foldri and foldr work from
right to left (decreasing indices). The more general functions foldli
and foldri supply f with the array index of the corresponding element.
See the MONO_ARRAY manual pages for reference implementations of the
indexed versions. The expression foldl f init arr is equivalent to
(foldli (fn (_, a, x) => f(a, x)) init arr). The analogous
equivalences hold for foldri and foldr.
These functions apply f to each element of the array arr,
from left to right (i.e., increasing indices), until a true value is
returned. If this occurs, the functions return the element; otherwise,
they return NONE. The more general version findi also supplies f with
the array index of the element and, upon finding an entry satisfying
the predicate, returns that index with the element.
applies f to each element x of the array arr, from left
to right (i.e., increasing indices), until f x evaluates to true; it
returns true if such an x exists and false otherwise.
applies f to each element x of the array arr, from left to
right (i.e., increasing indices), until f x evaluates to false; it
returns false if such an x exists and true otherwise. It is equivalent
to not(exists (not o f) arr)).