(* sieve-skeleton.sml *) (* 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; (* type of infinite streams and a supporting type *) datatype 'a stream' = Cons of 'a * 'a stream withtype 'a stream = 'a stream' susp; (* val from' : int -> int stream' val from : int -> int stream *) fun from' n = Cons(n, from(n + 1)) and from n = delay(fn () => from' n);