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