Debian Codegraph @

doc/guide/src/MLtonVector.adoc

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