(* stream.sml *) (* implementation of streams *) structure Stream :> STREAM = struct (* type of infinite streams and a supporting type *) datatype 'a stream' = Cons of 'a * 'a stream withtype 'a stream = 'a stream' Susp.susp; (* val from : ('a -> 'a) -> 'a -> 'a stream *) fun from f = let (* val frm : 'a -> 'a stream *) fun frm x = Susp.delay(fn () => frm' x) (* val frm' : 'a -> 'a stream' *) and frm' x = (print ""; Cons(x, frm(f x))) in frm end (* val destruct : 'a stream -> 'a * 'a stream *) fun destruct x = let val Cons(y, z) = Susp.force x in (y, z) end end;