List

Sort

sort List a = | Nil | Cons a * List a

Ops

Name Fixity Sort Description
nil  fa(a) List a the empty list
null  fa(a) List a -> Boolean true for empty lists
length  List a -> Nat length of a list
cons  fa(a) a * List a -> List a constructs a list consisting of a first element and a list tail
insert  fa(a) a * List a -> List a same as cons
hd  fa(a) List a -> a returns the first element of the list
tl  fa(a) List a -> List a returns the list tail without the first element
++ infixl 11 fa(a) List a * List a -> List a list concatenation
@ infixl 11 fa(a) List a * List a -> List a same as ++
concat  fa(a) List a * List a -> List a prefix op for list concatenation
flatten  fa(a) List(List(a)) -> List a returns the concatenation of the list elements
diff  fa(a) List a * List a -> List a list subtraction: diff(x,y) returns a list containing the elements of x that are not in y, preserving the order of the elements in x
member  fa(a) a * List a -> Boolean list membership
nth  fa(a) List a * Nat -> a returns the element at position n of a list, counting from 0
nthTail  fa(a) List a * Nat -> List a returns the list tail starting after position n, counting from 0
foldl  fa(a,b) (a*b -> b) -> b -> List a -> b foldl f e x successively applies function f to the elements of x from left to right. The second argument to f is initially e and at each step the result of the previous invocation of f
foldr  fa(a,b) (a*b -> b) -> b -> List a -> b like foldl, but the elements of the list are processed from right to left
map  fa(a,b) (a->b) -> List a -> List b applies function to each element of a list and returns the list consisting of the results
mapPartial  fa(a,b) (a->Option b) -> List a -> List b like map but replacing each result Some y by y and deleting None results.
filter  fa(a) (a -> Boolean) -> List a -> List a returns the list of elements satisfying the given predicate
rev  fa(a) List a -> List a reverse list
all  fa(a) (a -> Boolean) -> List a -> Boolean true if all elements of the list satisfy the predicate given as first parameter
exists  fa(a) (a->Boolean) -> List a -> Boolean true if some element of the list satisfies the predicate given as first parameter
find  fa(a) (a -> Boolean) -> List a -> Option(a) returns Some x where x is the first element in the list (from left to right) for which the given predicate yields true; if no such element exists, None is returned
tabulate  fa(a) Nat * (Nat -> a) -> List a tabulate(n, f) returns the list [f(0), f(1), ... , f(n-1)]
firstUpTo  fa(a) (a -> Boolean) -> List a -> Option (a * List a) returns Some(e, x) where e is the first element in the list (from left to right) satisfying the given predicate and x the initial list segment preceding e; if no such element exists, None is returned
splitList  fa(a) (a -> Boolean) -> List a -> Option (List a * a * List a) returns Some(x, e, y) where e is the first element in the list (from left to right) satisfying the given predicate, x the initial list segment preceding e, and y the list tail following e; if no such element exists, None is returned
locationOf  fa(a) List a * List a -> Option (Nat * List a) locationOf(s, t) returns Some(n, x) where n is the first position in list t (counting from from left to right) where list s occurs as a contiguous sublist, and x the list tail segment following s in t; if s does not occur in t, None is returned
compare  fa(a) (a * a -> Comparison) -> List a * List a -> Comparison compares two list using the comparison function given as first parameter
show  fa(a) String -> List String -> String show(s, x) returns the element strings in x concatenated, with string s inserted between any two elements