Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / MLtonVector.adoc
CommitLineData
7f918cf1
CE
1MLtonVector
2===========
3
4[source,sml]
5----
6signature MLTON_VECTOR =
7 sig
8 val create: int -> {done: unit -> 'a vector,
9 sub: int -> 'a,
10 update: int * 'a -> unit}
11 val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a vector * 'b
12 end
13----
14
15* `create n`
16+
17initiates the construction a vector _v_ of length `n`, returning
18functions to manipulate the vector. The `done` function may be called
19to return the created vector; it is an error to call `done` before all
20entries have been initialized; it is an error to call `done` after
21having called `done`. The `sub` function may be called to return an
22initialized vector entry; it is not an error to call `sub` after
23having called `done`. The `update` function may be called to
24initialize a vector entry; it is an error to call `update` after
25having called `done`. One must initialize vector entries in order
26from lowest to highest; that is, before calling `update (i, x)`, one
27must have already called `update (j, x)` for all `j` in `[0, i)`. The
28`done`, `sub`, and `update` functions are all constant-time
29operations.
30
31* `unfoldi (n, b, f)`
32+
33constructs a vector _v_ of length `n`, whose elements __v~i~__ are
34determined by the equations __b~0~ = b__ and
35__(v~i~, b~i+1~) = f (i, b~i~)__.