The MONO_VECTOR_SLICE signature provides an abstraction of subarrays
for monomorphic immutable arrays or vectors. A slice value can be
viewed as a triple (v, i, n), where v is the underlying vector, i is
the starting index, and n is the length of the subarray, with the
constraint that 0 <= i <= i + n <= |v|, where |v| is the length of the
vector v. Slices provide a convenient notation for specifying and
operating on a contiguous subset of elements in a vector.
creates a slice based on the vector vec starting
at index i of the vector vec. If sz is NONE, the slice includes all of
the elements to the end of the vector, i.e., vec[i..|vec|-1]. This
raises Subscript if i < 0 or |vec| < i. If sz is SOME(j), the slice
has length j, that is, it corresponds to vec[i..i+j-1]. It raises
Subscript if i < 0 or j < 0 or |vec| < i + j. Note that, if defined,
slice returns an empty slice when i = |vec|.
creates a slice based on the given slice sl
starting at index i of sl. If sz is NONE, the slice includes all of
the elements to the end of the slice, i.e., sl[i..|sl|-1]. This raises
Subscript if i < 0 or |sl| < i. If sz is SOME(j), the slice has length
j, that is, it corresponds to sl[i..i+j-1]. It raises Subscript if i <
0 or j < 0 or |sl| < i + j. Note that, if defined, slice returns an
empty slice when i = |sl|.
returns a triple (vec, i, n) representing the concrete
representation of the slice. vec is the underlying vector, i is the
starting index, and n is the length of the slice.
generates a vector from the slice sl. Specifically, if vec
is the resulting vector, we have |vec| = |sl| and, for 0 <= i < |sl|,
element i of vec is sub (sl, i).
is the concatenation of all the vectors in l. This raises
Size if the sum of all the lengths is greater than the maximum length
allowed by vectors of type vector.
These apply the function f to the elements of a slice in
left to right order (i.e., increasing indices). The more general appi
function supplies f with the index of the corresponding element in the
slice. The expression app f sl is equivalent to appi (f o #2) sl.
These functions generate new vectors by mapping the
function f from left to right over the argument slice. The more
general mapi function supplies both the element and the element's
index in the slice to the function f. The latter expression is
equivalent to (mapi (f o #2) sl).
These fold the function f over all the elements of
a vector slice, 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 index of the corresponding element in the
slice. See the MONO_ARRAY manual pages for reference implementations
of the indexed versions. The expression foldl f init sl is equivalent
to (foldli (fn (_, a, x) => f(a, x)) init sl). The analogous
equivalence holds for foldri and foldr.
These apply f to each element of the slice sl, 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 index of the element in the slice and, upon finding an entry
satisfying the predicate, returns that index with the element.
applies f to each element x of the slice sl, 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 slice sl, 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) sl)).