Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / doc / guide / src / MLtonCont.adoc
1 MLtonCont
2 =========
3
4 [source,sml]
5 ----
6 signature MLTON_CONT =
7 sig
8 type 'a t
9
10 val callcc: ('a t -> 'a) -> 'a
11 val isolate: ('a -> unit) -> 'a t
12 val prepend: 'a t * ('b -> 'a) -> 'b t
13 val throw: 'a t * 'a -> 'b
14 val throw': 'a t * (unit -> 'a) -> 'b
15 end
16 ----
17
18 * `type 'a t`
19 +
20 the type of continuations that expect a value of type `'a`.
21
22 * `callcc f`
23 +
24 applies `f` to the current continuation. This copies the entire
25 stack; hence, `callcc` takes time proportional to the size of the
26 current stack.
27
28 * `isolate f`
29 +
30 creates a continuation that evaluates `f` in an empty context. This
31 is a constant time operation, and yields a constant size stack.
32
33 * `prepend (k, f)`
34 +
35 composes a function `f` with a continuation `k` to create a
36 continuation that first does `f` and then does `k`. This is a
37 constant time operation.
38
39 * `throw (k, v)`
40 +
41 throws value `v` to continuation `k`. This copies the entire stack of
42 `k`; hence, `throw` takes time proportional to the size of this stack.
43
44 * `throw' (k, th)`
45 +
46 a generalization of throw that evaluates `th ()` in the context of
47 `k`. Thus, for example, if `th ()` raises an exception or captures
48 another continuation, it will see `k`, not the current continuation.
49
50
51 == Also see ==
52
53 * <:MLtonContIsolateImplementation:>