The List structure provides a collection of utility functions for
manipulating polymorphic lists, traditionally an important datatype in
functional programming.
Following the concrete syntax provided by the list :: operator, the
head of a list appears leftmost. Thus, a traversal of a list from left
to right starts with the head, then recurses on the tail. In addition,
as a sequence type, a list has an indexing of its elements, with the
head having index 0, the second element having index 1, etc.
structure List : LIST
signature LIST =
sigeqtype 'a list
exception Empty
valnull : 'a list -> bool
vallength : 'a list -> int
val@ : 'a list * 'a list -> 'a list
valhd : 'a list -> 'a
valtl : 'a list -> 'a list
vallast : 'a list -> 'a
valgetItem : 'a list -> ('a * 'a list) option
valnth : 'a list * int -> 'a
valtake : 'a list * int -> 'a list
valdrop : 'a list * int -> 'a list
valrev : 'a list -> 'a list
valconcat : 'a list list -> 'a list
valrevAppend : 'a list * 'a list -> 'a list
valapp : ('a -> unit) -> 'a list -> unit
valmap : ('a -> 'b) -> 'a list -> 'b list
valmapPartial : ('a -> 'b option) -> 'a list -> 'b list
valfind : ('a -> bool) -> 'a list -> 'a option
valfilter : ('a -> bool) -> 'a list -> 'a list
valpartition : ('a -> bool)
-> 'a list -> 'a list * 'a list
valfoldl : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
valfoldr : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
valexists : ('a -> bool) -> 'a list -> bool
valall : ('a -> bool) -> 'a list -> bool
valtabulate : int * (int -> 'a) -> 'a list
valcollate : ('a * 'a -> order)
-> 'a list * 'a list -> order
end
[type 'a list]
is considered a primitive type and is defined in the
top-level environment. It is rebound here for consistency.
[exception Empty]
This exception indicates that an empty list was
given as an argument to a function requiring a non-empty list.
returns NONE if the list is empty, and SOME(hd l,tl l)
otherwise. This function is particularly useful for creating value
readers from lists of characters. For example, Int.scan StringCvt.DEC
getItem has the type
(int,char list) StringCvt.reader
and can be used to scan decimal integers from lists of characters.
returns what is left after dropping the first i elements
of the list l. It raises Subscript if i < 0 or i > length l. It holds
that take(l, i) @ drop(l, i) = l when 0 <= i <= length l. We also have
drop(l, length l) = [].
applies f to each element of l from left to right,
returning a list of results, with SOME stripped, where f was
defined. f is not defined for an element of l if f applied to the
element returns NONE. The above expression is equivalent to:
applies f to each element x of the list l, from left to
right, until f x evaluates to true. It returns SOME(x) if such an x
exists; otherwise it returns NONE.
applies f to each element x of l, from left to right, and
returns the list of those x for which f x evaluated to true, in the
same order as they occurred in the argument list.
applies f to each element x of l, from left to right,
and returns a pair (pos, neg) where pos is the list of those x for
which f x evaluated to true, and neg is the list of those for which f
x evaluated to false. The elements of pos and neg retain the same
relative order they possessed in l.
applies f to each element x of the list l, from left to
right, 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)
l)).