equal
deleted
inserted
replaced
6 attempts of evaluation -- the first result persists. |
6 attempts of evaluation -- the first result persists. |
7 *) |
7 *) |
8 |
8 |
9 signature LAZY = |
9 signature LAZY = |
10 sig |
10 sig |
11 type 'a T |
11 type 'a lazy |
12 val same: 'a T * 'a T -> bool |
12 val same: 'a lazy * 'a lazy -> bool |
13 val lazy: (unit -> 'a) -> 'a T |
13 val lazy: (unit -> 'a) -> 'a lazy |
14 val value: 'a -> 'a T |
14 val value: 'a -> 'a lazy |
15 val peek: 'a T -> 'a Exn.result option |
15 val peek: 'a lazy -> 'a Exn.result option |
16 val force: 'a T -> 'a |
16 val force: 'a lazy -> 'a |
17 val map_force: ('a -> 'a) -> 'a T -> 'a T |
17 val map_force: ('a -> 'a) -> 'a lazy -> 'a lazy |
18 end |
18 end |
19 |
19 |
20 structure Lazy :> LAZY = |
20 structure Lazy :> LAZY = |
21 struct |
21 struct |
22 |
22 |
23 (* datatype *) |
23 (* datatype *) |
24 |
24 |
25 datatype 'a lazy = |
25 datatype 'a T = |
26 Lazy of unit -> 'a | |
26 Lazy of unit -> 'a | |
27 Result of 'a Exn.result; |
27 Result of 'a Exn.result; |
28 |
28 |
29 type 'a T = 'a lazy ref; |
29 type 'a lazy = 'a T ref; |
30 |
30 |
31 fun same (r1: 'a T, r2) = r1 = r2; |
31 fun same (r1: 'a lazy, r2) = r1 = r2; |
32 |
32 |
33 fun lazy e = ref (Lazy e); |
33 fun lazy e = ref (Lazy e); |
34 fun value x = ref (Result (Exn.Result x)); |
34 fun value x = ref (Result (Exn.Result x)); |
35 |
35 |
36 fun peek r = |
36 fun peek r = |
56 in Exn.release res' end; |
56 in Exn.release res' end; |
57 |
57 |
58 fun map_force f = value o f o force; |
58 fun map_force f = value o f o force; |
59 |
59 |
60 end; |
60 end; |
|
61 |
|
62 type 'a lazy = 'a Lazy.lazy; |
|
63 |