MONO_ARRAY
signature
The MONO_ARRAY signature is a generic interface to monomorphic mutable sequences. Arrays also 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.
signature MONO_ARRAY
structure Word8Array
: MONO_ARRAY
structure CharArray
: MONO_ARRAY
structure WideCharArray
: MONO_ARRAY
structure BoolArray
: MONO_ARRAY
structure IntArray
: MONO_ARRAY
structure RealArray
: MONO_ARRAY
structure Int{N}Array
: MONO_ARRAY
structure Real{N}Array
: MONO_ARRAY
eqtype array
type elem
structure Vector : MONO_VECTOR
val maxLen : int
val array : (int * elem) -> array
val fromList : elem list -> array
val tabulate : (int * (int -> elem)) -> array
val length : array -> int
val sub : (array * int) -> elem
val update : (array * int * elem) -> unit
val extract : (array * int * int option) -> Vector.vector
val copy : {src : array, si : int, len : int option, dst : array, di : int} -> unit
val copyVec : {src : Vector.vector, si : int, len : int option, dst : array, di : int} -> unit
val appi : ((int * elem) -> unit) -> (array * int * int option) -> unit
val app : (elem -> unit) -> array -> unit
val foldli : ((int * elem * 'b) -> 'b) -> 'b -> (array * int * int option) -> 'b
val foldri : ((int * elem * 'b) -> 'b) -> 'b -> (array * int * int option) -> 'b
val foldl : ((elem * 'b) -> 'b) -> 'b -> array -> 'b
val foldr : ((elem * 'b) -> 'b) -> 'b -> array -> 'b
val modifyi : ((int * elem) -> elem) -> (array * int * int option) -> unit
val modify : (elem -> elem) -> array -> unit
eqtype array
type elem
structure Vector
maxLen
array (n, init)
maxLen
< n, then the Size exception is raised.
fromList l
tabulate (n, f)
fromList (List.tabulate (n, f))If n < 0 or
maxLen
< n, then the Size exception is raised.
length arr
sub (arr, i)
update (arr, i, x)
extract slice
copy {src, si, len, dst, di}
copyVec {src, si, len, dst, di}
(src, si, len)
into the array dst, with element si being copied to position di in the destination array. The function copy takes an array slice as its source, while the function copyVec
uses a vector slice. If the source slice is not valid, then the Subscript exception is raised. Likewise, if di < 0 or if |dst| < di+n, where n is the number of elements copied, then the Subscript exception is raised.
Implementation note:
The
copy
function must correctly handle the case in which src and dst are equal, and the source and destination slices overlap.
appi f slice
app f arr
The function app applies f to the whole array and does not supply the element index to f. Thus the expression app f arr
is equivalent to:
appi (f o #2) (arr, 0, NONE)
foldli f init slice
foldri f init slice
foldl f init arr
foldr f init arr
The functions foldl and foldr work on the whole array arr and do not supply the element index to f. Thus the expression foldl f init arr
is equivalent to:
foldl (fn (_, a, x) => f(a, x)) init (arr, 0, NONE)
Example:
One can extract the list of elements in an array arr by the expression:
foldr (op ::) [] arr
modifyi f slice
modify f arr
The function modify
applies f to the whole array and does not supply the element index to f. Thus the expression modify f arr
is equivalent to:
modifyi (f o #2) (arr, 0, NONE)
Array, MONO_VECTOR
Last Modified April 16, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies