The Standard ML Basis Library


The MONO_VECTOR signature

The MONO_VECTOR signature is a generic interface to monomorphic immutable sequences.


Synopsis

signature MONO_VECTOR
structure Word8Vector : MONO_VECTOR
structure CharVector : MONO_VECTOR
structure WideCharVector : MONO_VECTOR
structure BoolVector : MONO_VECTOR
structure IntVector : MONO_VECTOR
structure RealVector : MONO_VECTOR
structure Int{N}Vector : MONO_VECTOR
structure Real{N}Vector : MONO_VECTOR

Interface

type vector
type elem
val maxLen : int
val fromList : elem list -> vector
val tabulate : (int * (int -> elem)) -> vector
val length : vector -> int
val sub : (vector * int) -> elem
val extract : (vector * int * int option) -> vector
val concat : vector list -> vector
val mapi : ((int * elem) -> elem) -> (vector * int * int option) -> vector
val map : (elem -> elem) -> vector -> vector
val appi : ((int * elem) -> unit) -> (vector * int * int option) -> unit
val app : (elem -> unit) -> vector -> unit
val foldli : ((int * elem * 'a) -> 'a) -> 'a -> (vector * int * int option) -> 'a
val foldri : ((int * elem * 'a) -> 'a) -> 'a -> (vector * int * int option) -> 'a
val foldl : ((elem * 'a) -> 'a) -> 'a -> vector -> 'a
val foldr : ((elem * 'a) -> 'a) -> 'a -> vector -> 'a

Description

type vector
type elem

maxLen
is the maximum length of vectors supported by this implementation. Attempts to create larger vectors will result in the Size exception being raised.

fromList l
creates a new vector from a list of elements. If the length of the list is greater than maxLen, then the Size exception is raised.

tabulate (n, f)
creates an vector 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.

length vec
returns |vec|, the length of the array vec.

sub (vec, i)
returns the ith element of the vector vec. If i < 0 or |vec| <= i, then the Subscript exception is raised.

extract slice
extracts the vector slice slice from the vector vec, and returns it as a vector. If the slice is not valid, then the exception Subscript is raised.

concat l
returns the vector that is the concatenation of the vectors in the list l. If the total length of these vectors exceeds maxLen, then the Size exception is raised.

mapi f slice
map f vec
produce new vectors by mapping the function f from left to right over the argument vector or slice. The more general mapi function applies f to the elements of the vector slice slice and supplies both the element and the element's index to the function f. If slice is not valid, then the exception Subscript is raised. The expression 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
apply the function f to the elements of a vector in left to right order (i.e., increasing indices). The more general appi function applies f to the elements of the vector slice slice and supplies both the element and the element's index to the function f. If slice is not valid, then the exception Subscript is raised.

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
fold the function f over the elements of a vector, 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 work on vector slices, and supply both the element and the element's index to the function f.

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
	    



Discussion

The type String.string is identical to CharVector.vector.

See Also

MONO_ARRAY, Vector

[ INDEX | TOP | Parent | Root ]

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