(* susp.sml *) (* implementation of suspensions *) structure Susp :> SUSP = struct (* the type of suspensions and a supporing type *) datatype 'a delay = Value of 'a | Delay of unit -> 'a type 'a susp = 'a delay ref (* val delay : (unit -> 'a) -> 'a susp *) fun delay f = ref(Delay f) (* val force : 'a susp -> 'a *) fun force(ref(Value x)) = x | force(r as ref(Delay f)) = let val x = f() in r := Value x; x end; end;