1(* Susp -- support for lazy evaluation 1995-05-22 *)
2structure Susp :> Susp =
3struct
4
5datatype 'a thunk = VAL of 'a | THUNK of unit -> 'a
6
7type 'a susp = 'a thunk ref
8
9fun delay (f : unit -> 'a) = ref (THUNK f) : 'a susp
10
11fun force (su : 'a susp) : 'a =
12   case !su of
13      VAL v   => v
14    | THUNK f => let val v = f () in su := VAL v; v end
15
16end (* struct *)
17