Debian Codegraph @

lib/mlrisc-lib/MLRISC/library/susp.sml

raw
1 (*
2 * Force/delay
3 *
4 * -- Allen
5 *)
6
7 signature SUSPENSION =
8 sig
9 type 'a susp
10 val $$ : (unit -> 'a) -> 'a susp
11 val !! : 'a susp -> 'a
12 end
13
14 structure Suspension :> SUSPENSION =
15 struct
16 datatype 'a thunk = VALUE of 'a | CLOSURE of unit -> 'a
17 type 'a susp = 'a thunk ref
18
19 fun $$ e = ref(CLOSURE e)
20 fun !! (ref (VALUE v)) = v
21 | !! (r as ref(CLOSURE e)) =
22 let val v = e()
23 in r := VALUE v; v end
24 end
25