List
Functions
map

Applies f to every element of the list and returns the new list.

Type Signature
<'a,'b,'closure;n>(||)(('closure)('a) -> 'b, list<'a; n>) -> list<'b; n>
Parameters
f : ('closure)('a) -> 'b

The mapping function

lst : list<'t;n>

The list to map.

Returns

The list obtained by applying f to every element of lst.

foldl

Applies a function f to each element of the list, threading an accumulator argument through the computation.

Type Signature
<'t,'state,'closure;n>(||)(('closure)('t, 'state) -> 'state, 'state, list<'t; n>) -> 'state
Parameters
f : ('closure)('t, 'state) -> 'state

The function to update the state given the input elements.

initState : 'state

The initial state.

lst : list<'t; n>

The input list.

Returns

The final state value.

foldr

Applies a function f to each element of the list in reverse order, threading an accumulator argument through the computation.

Type Signature
<'t,'state,'closure;n>(||)(('closure)('t, 'state) -> 'state, 'state, list<'t; n>) -> 'state
Parameters
f : ('closure)('t,'state) -> 'state

The function to update the state given the input elements.

initState : 'state

The initial state.

lst : list<'t; n>

The input list.

Returns

The final state value.

append

Appends two lists.

Type Signature
<'t;aCap,bCap,retCap>(||)(list<'t;aCap>, list<'t;bCap>) -> list<'t;retCap>
Parameters
lstA : list<'t;aCap>

The first list.

lstB : list<'t;bCap>

The second list.

Returns

The two lists appended together.

nth

Returns the nth element of the given list

Type Signature
<'t;n>(||)(uint32, list<'t;n>) -> 't
Parameters
i : uint32

The index of the element to be retrieved

lst : list<'t;n>

The given list

Returns

The element at position i in the list

flattenSafe

Flattens a list of lists into a single list.

Type Signature
<'t;m,n>(||)(list<list<'t;m>;n>) -> list<'t;m*n>
Parameters
listOfLists : list<list<'t;m>;n>

The list of lists

Returns

The flattened list

resize

Creates a copy of the list which has a new capacity m. The contents and length of the list remained unchanged.

Type Signature
<'t;n,m>(||)(list<'t;n>) -> list<'t;m>
Parameters
lst : list<'t;n>

The list to resize

Returns

The new list with capacity m

all

Returns true if pred(elem) returns true for all elements elem in lst, otherwise false.

Type Signature
<'t,'closure;n>(||)(('closure)('t) -> bool, list<'t;n>) -> bool
Parameters
pred : ('closure)('t) -> bool

The predicate which must be satisfied

lst : list<'t;n>

The list on which the predicate is checked

Returns

A boolean value which determines if pred satsified for every element of lst.

any

Returns true if pred(elem) returns true for at least one element elem in lst, otherwise false.

Type Signature
<'t,'closure;n>(||)(('closure)('t) -> bool, list<'t;n>) -> bool
Parameters
pred : ('closure)('t) -> bool

The predicate which must be satisfied

lst : list<'t;n>

The list on which the predicate is checked

Returns

A boolean value which determines if pred is satsified for some element of lst.

pushBack

Returns a copy of the given list with the element appended to the end.  If the element will not fit in the list, the program crashes.

Type Signature
<'t;n>(||)('t, list<'t;n>) -> list<'t;n>
Parameters
elem : 't

The element to add to the end of the list

lst : list<'t;n>

The list

Returns

A copy of lst with elem appended to the end

pushOffFront

Returns a copy of the given list with the element appended to the front.  If the list is already full then the last element is pushed off (removed) from the back of the list.

Type Signature
<'t;n>(||)('t, list<'t;n>) -> list<'t;n>
Parameters
elem : 't

The element to add to the front of the list

lst : list<'t;n>

The list

Returns

A copy of lst with elem appended to the front

setNth

Returns a copy of the given list where the element at the given index is the given element.

Type Signature
<'t;n>(||)(uint32, 't, list<'t;n>) -> list<'t;n>
Parameters
index : uint32

The index to set

elem : 't

The new element

lst : list<'t;n>

The list

Returns

A new list where the elem is at index.

replicate

Initializes a new list of a given length using the given element.

Type Signature
<'t;n>(||)(uint32, 't) -> list<'t;n>
Parameters
numOfElements : uint32

The length of the new list

elem : 't

The element to replicate

Returns

A new list with elem at every position in the list.

remove

Returns a copy of lst where the first element equal to elem is deleted, if there is such an element.

Type Signature
<'t;n>(||)('t, list<'t;n>) -> list<'t;n>
Parameters
elem : 't

The element to remove from the list

lst : 't

The list

Returns

A copy of lst with elem removed.

dropLast

Drops the last element of a List. The list should be non-empty, otherwise the program will exit.

Type Signature
<'t;n>(||)(list<'t;n>) -> list<'t;n>
Parameters
lst : list<'t;n>

The list

Returns

The list with the last element dropped

foreach

Calls f for each element in lst. This function is used for its side effects and the evaluation order is defined to be the same as the order of the elements in the list.

Type Signature
<'t,'closure;n>(||)(('closure)('t) -> unit, list<'t;n>) -> unit
Parameters
f : ('closure)('t) -> unit

The function to call

lst : list<'t;n>

The list

Returns

Unit

last

Returns the last element of the lst.

Type Signature
<'t;n>(||)(list<'t;n>) -> 't
Parameters
lst : list<'t;n>

The list

Returns

The last element of the list

max_

Returns the maximum element of the lst. The program exits if the list has no elements.

Type Signature
<'t;n>(||)(list<'t;n>) -> 't where 't : num
Parameters
lst : list<'t;n>

The list

Returns

The maximum element of the list

min_

Returns the minimum element of the lst. The program exits if the list has no elements.

Type Signature
<'t;n>(||)(list<'t;n>) -> 't where 't : num
Parameters
lst : list<'t;n>

The list

Returns

The minimum element of the list

member

Returns true if elem is a member of lst, otherwise false.

Type Signature
<'t;n>(||)('t, list<'t;n>) -> bool
Parameters
elem : 't

The element to match

lst : list<'t;n>

The list to search

Returns

True if elem is in the list, otherwise false.

zip

Zips two lists of equal length into one list of two-tuples, where the first element of each tuple is taken from the first list and the second element is taken from corresponding element in the second list. If the lists are not of equal length, the program exits.

Type Signature
<'a,'b;n>(||)(list<'a;n>, list<'b;n>) -> list<('a*'b);n>
Parameters
lstA : list<'a;n>

The first list to zip

lstB : list<'b;n>

The second list to zip

Returns

The zipped lists.

unzip

Unzips a list of two-tuples into two lists, where the first list contains the first element of each tuple, and the second list contains the second element of each tuple.

Type Signature
<'a,'b;n>(||)(list<('a*'b);n>) -> (list<'a;n>*list<'b;n>)
Parameters
lst : list<('a*'b);n>

The list to unzip

Returns

The two unzipped lists.

sum

Computes the sum of a list of numbers

Type Signature
<'a;n>(||)(list<'a;n>) -> 'a where 'a : num
Parameters
lst : list<'a;n>

The list to sum

Returns

The sum of the list

average

Computes the average (mean) of a list of numbers

Type Signature
<'a;n>(||)(list<'a;n>) -> 'a where 'a : num
Parameters
lst : list<'a;n>

The list to average

Returns

The numerical mean of the list