A sequence is a view on a store. It is possible to iterate over
the elements of the sequence in normal order. One can also add new
elements to the end of a sequence, and get a new sequence where
the new elements are found at the end.

A sequence is always bound to a store. The store is the entity
which is modified by sequence operations. The sequence as such
behaves as if it were immutable (like a list).

All the following operations are only executed locally (no
distribution).

type('a, 'b) seq

A sequence (el,mode) seq contains elements of type el,
and can be accessed according to mode:

let s2 = add x s1: Adds the element to the underlying store,
and returns a new sequence where the new element is visible at
the end. This means the last element of s2 is now x. The
view provided by s1 does not change.

It is a requirement that the last element of s1 is the last
element of the underlying store. Otherwise the add fails.

sort ~hash ~cmp s1 s2: Sorts the elements of s1 and appends
the sorted result to s2, and returns this sequence.

It is first sorted by the value hash x of each element of s1.
If this results in the same value for two elements x and y,
these elements are directly compared with cmp x y.

The function hash may return a non-negative 30 bit wide integer.
cmp can return 0 meaning equality, a positive number meaning
that that the first argument is bigger, or a negative number
meaning that the second argument is bigger.

where P=partitions. Each s(k) is the result of applying
a fold pass to p(k) which is defined below. The list

[p0; p1; ...; p(P-1)]

are the sequences containing the sorted and mapped input,
split into P partitions. In particular, the partition
p(k) contains the sorted elements x where
partition_of x = k. The elements x are taken from
the set M = { mapl(y) | y in p_in} .

The sorting criterion is defined by hash and cmp. In order
to decide the order of the elements x of p(k), the elements
are first compared by hash x. If for two elements x1 and
x2 the value hash x1 is smaller than hash x2, x1 is
sorted before x2. If hash x1 is bigger than hash x2,
x1 is sorted after x2. If the hash values are identical,
the function cmp x1 x2 is called, and if a negative value
is returned, x1 is sorted before x2, and if a positive
value is returned, x1 is sorted after x2. The result 0
means that x1 and x2 are considered equal.