Vector
structureThe Vector structure provides polymorphic immutable sequences.
signature VECTOR
structure Vector
: VECTOR
eqtype 'a vector
val maxLen : int
val fromList : 'a list -> 'a vector
val tabulate : (int * (int -> 'a)) -> 'a vector
val length : 'a vector -> int
val sub : ('a vector * int) -> 'a
val extract : ('a vector * int * int option) -> 'a vector
val concat : 'a vector list -> 'a vector
val mapi : ((int * 'a) -> 'b) -> ('a vector * int * int option) -> 'b vector
val map : ('a -> 'b) -> 'a vector -> 'b vector
val appi : ((int * 'a) -> unit) -> ('a vector * int * int option) -> unit
val app : ('a -> unit) -> 'a vector -> unit
val foldli : ((int * 'a * 'b) -> 'b) -> 'b -> ('a vector * int * int option) -> 'b
val foldri : ((int * 'a * 'b) -> 'b) -> 'b -> ('a vector * int * int option) -> 'b
val foldl : (('a * 'b) -> 'b) -> 'b -> 'a vector -> 'b
val foldr : (('a * 'b) -> 'b) -> 'b -> 'a vector -> 'b
eqtype 'a vector
maxLen
fromList l
tabulate (n, f)
fromList (List.tabulate (n, f))If n < 0 or
maxLen
< n, then the Size exception is raised.
length vec
sub (vec, i)
extract slice
concat l
mapi f slice
map f vec
mapi f slice
is equivalent to:
fromList (List.map f (foldri (fn (i,a,l) => (i,a)::l) [] slice))
The function map applies f to the whole vector and does not supply the element index to f. Thus the expression map f vec
is equivalent to:
mapi (f o #2) (vec, 0, NONE)
appi f slice
app f vec
The function app applies f to the whole vector and does not supply the element index to f. Thus the expression app f vec
is equivalent to:
appi (f o #2) (vec, 0, NONE)
foldli f init slice
foldri f init slice
foldl f init vec
foldr f init vec
The functions foldl and foldr work on the whole vector vec and do not supply the element index to f. Thus the expression foldl f init vec
is equivalent to:
foldli (fn (_, a, x) => f(a, x)) init (vec, 0, NONE)
Example:
One can extract the list of elements in a vector vec by the expression:
foldr (op ::) [] vec
Array, MONO_VECTOR
Last Modified January 21, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies