signature DELAY = sig type 'a T (* type of delayed computations *) val delay : (unit -> 'a) -> 'a T (* create delayed computation *) val force : 'a T -> 'a (* execute and memoize computation *) val trivial : 'a -> 'a T (* create trivial delayed computation *) end structure Delay : DELAY = (* Facilities for delayed, memoized computations are built into *) (* SML/NJ in the structure System.Unsafe.Susp. (There is nothing *) (* unsafe about these operations; they appear in System.Unsafe for *) (* historical reasons.) The advantage to using the built-in *) (* functions instead of implementing delay and force in terms of *) (* ref cells is that we can avoid weak polymorphism. *) struct type 'a T = 'a System.Unsafe.Susp.susp val delay = System.Unsafe.Susp.delay val force = System.Unsafe.Susp.force fun trivial x = delay (fn () => x) end