# alice library manual. # The MONO_ARRAY_SLICE signature

## ________ Synopsis ____________________________________________________

```    signature MONO_ARRAY_SLICE
structure CharArraySlice : MONO_ARRAY_SLICE
where type elem         = char
and type vector       = string
and type vector_slice = substring
and type array        = CharArray.t
structure Word8ArraySlice : MONO_ARRAY_SLICE
where type elem         = Word8.t
and type vector       = Word8Vector.t
and type vector_slice = Word8VectorSlice.t
and type array        = Word8Array.t
```

An extended version of the Standard ML Basis' MONO_ARRAY_SLICE signature.

## ________ Import ______________________________________________________

Imported implicitly.

## ________ Interface ___________________________________________________

```    signature MONO_ARRAY_SLICE =
sig
type elem
type vector
type vector_slice
type array
type slice
type t = slice

val full :        array -> slice
val slice :       array * int * int option -> slice
val subslice :    slice * int * int option -> slice
val vector :      slice -> vector
val toVector :    slice -> vector
val toList :      slice -> elem list

val length :      slice -> int
val isEmpty :     slice -> bool
val base :        slice -> array * int * int
val sub :         slice * int -> elem
val update :      slice * int * elem -> unit
val swap :        slice * int * int -> unit
val getItem :     slice -> (elem * slice) option

val triml :       int -> slice -> slice
val trimr :       int -> slice -> slice
val splitAt :     slice * int -> slice * slice
val splitl :      (elem -> bool) -> slice -> slice * slice
val splitr :      (elem -> bool) -> slice -> slice * slice
val dropl :       (elem -> bool) -> slice -> slice
val dropr :       (elem -> bool) -> slice -> slice
val takel :       (elem -> bool) -> slice -> slice
val taker :       (elem -> bool) -> slice -> slice

val rev :         slice -> unit
val copy :        {src : slice,  dst : array, di : int} -> unit
val copyVec :     {src : vector_slice, dst : array, di : int} -> unit

val app :         (elem -> unit) -> slice -> unit
val appr :        (elem -> unit) -> slice -> unit
val modify :      (elem -> elem) -> slice -> unit
val foldl :       (elem * 'a -> 'a) -> 'a -> slice -> 'a
val foldr :       (elem * 'a -> 'a) -> 'a -> slice -> 'a
val all :         (elem -> bool) -> slice -> bool
val exists :      (elem -> bool) -> slice -> bool
val find :        (elem -> bool) -> slice -> elem option

val appi :        (int * elem -> unit) -> slice -> unit
val appri :       (int * elem -> unit) -> slice -> unit
val modifyi :     (int * elem -> elem) -> slice -> unit
val foldli :      (int * elem * 'a -> 'a) -> 'a -> slice -> 'a
val foldri :      (int * elem * 'a -> 'a) -> 'a -> slice -> 'a
val alli :        (int * elem -> bool) -> slice -> bool
val existsi :     (int * elem -> bool) -> slice -> bool
val findi :       (int * elem -> bool) -> slice -> (int * elem) option

val contains :    (elem * elem -> bool) -> slice -> elem -> bool
val notContains : (elem * elem -> bool) -> slice -> elem -> bool

val equal :       (elem * elem -> bool) -> slice * slice -> bool
val collate :     (elem * elem -> order) -> slice * slice -> order

val isSorted :    (elem * elem -> order) -> slice -> bool
val sort :        (elem * elem -> order) -> slice -> unit
end
```

## ________ Description _________________________________________________

Items not described here are as in the Standard ML Basis' MONO_ARRAY_SLICE signature.

type t = slice

A local synonym for type slice.

toVector sl

Creates a vector of the elements of sl. Equivalent to vector sl.

toList sl

Creates a list of the elements of sl in order of increasing indices.

rev sl

Reverses in-place the order of elements in the slice sl.

swap (sl, i, j)

Swaps the ith and jth element of slice sl. If i < 0 or |sl| <= i, or j < 0 or |sl| <= j, then the Subscript exception is raised.

triml k sl
trimr k sl

These functions remove k elements from the left (respectively, right) of the slice sl. If k is greater than the size of the slice, an empty slice is returned. Specifically, for a slice sl = slice(arr,i,j) and kj, we have:

```        triml k sl = slice(arr, i+k, j-k)
trimr k sl = slice(arr, i, j-k)```

The exception Subscript is raised if k < 0. This exception is raised when triml k or trimr k is evaluated.

splitAt (sl, i)

Returns the pair of slices (sl1, sl2), where sl1 contains the first i characters of sl and sl2 contains the rest, assuming 0 ≤ isize sl. Otherwise, it raises Subscript.

splitl f sl
splitr f sl

These functions scan sl from left to right (respectively, right to left) looking for the first element that does not satisfy the predicate f. They return the pair (sl1, sl2) giving the split of the slice into the span up to that element and the rest. The slice sl1 is the left side of the split, sl2the right side.

dropl f sl
dropl f sl
takel f sl
taker f sl

These routines scan the slice sl for the first element not satisfying the predicate f. The functions dropl and takel scan left to right (i.e., increasing indices), while dropr and taker scan from the right. The drop functions drop the maximal subslice consisting of elements satisfying the predicate, while the take functions return the maximal such subslice. These can be defined in terms of the split operations:

```        takel f sl = #1(splitl f sl)
dropl f sl = #2(splitl f sl)
taker f sl = #2(splitr f sl)
dropr f sl = #1(splitr f sl)```
appr f sl
appri f sl

Like app and appi, but apply f in right to left order (i.e., decreasing indices). The expression appr f sl is equivalent to:

`        appri (f o #2) sl`
alli f sl
existsi f sl

Indexed versions of the functions all and exists. The index of each element is passed to f as an additional argument. The following equivalences hold:

```        all f sl    = alli (f o #2) sl
exists f sl = existsi (f o #2) sl```
contains eq sl a

Returns true if the element a occurs in the slice sl, with respect to the element equality eq; otherwise false.

notContains eq sl a

Returns true if the element a does not occur in the slice sl, with respect to the element equality eq; otherwise false. Equivalent to not(contains eq sl a).

equal eq (sl1, sl2)

Creates an equality function on slices given an equality on the element type.

isSorted f sl

Returns true iff the elements in sl are sorted with respect to the ordering function f.

sort f sl

Sorts the elements in the slice sl with respect to the ordering function f. Sorting may be unstable with respect to equal elements.
{"ft_lang_label":"__label__en","ft_lang_prob":0.55037814,"math_prob":0.9764619,"size":5553,"snap":"2019-26-2019-30","text_gpt3_token_len":1446,"char_repetition_ratio":0.23463687,"word_repetition_ratio":0.22673893,"special_character_ratio":0.30722132,"punctuation_ratio":0.12934363,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97554445,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-21T15:42:41Z\",\"WARC-Record-ID\":\"<urn:uuid:a2f375cb-862e-4863-a624-804068c60136>\",\"Content-Length\":\"11835\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:504aac6d-2d29-4caf-8b76-6ee20f347e6b>\",\"WARC-Concurrent-To\":\"<urn:uuid:37df1f12-1440-4ada-a54a-8f856398ed6d>\",\"WARC-IP-Address\":\"134.96.186.68\",\"WARC-Target-URI\":\"https://www.ps.uni-saarland.de/alice/manual/library/mono-array-slice.html\",\"WARC-Payload-Digest\":\"sha1:CGWNXFON7HA72RAB6CJVZSMXMF24QNKS\",\"WARC-Block-Digest\":\"sha1:OYDZ4X3KGMJJAHXVJLVWLNLAOLEALJHO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195527048.80_warc_CC-MAIN-20190721144008-20190721170008-00306.warc.gz\"}"}