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