signature STREAM = sig type 'a stream val make : ('a * ('a -> 'a)) -> 'a stream val next : 'a stream -> ('a * 'a stream) val make2 : ('b * ('b -> 'a*'b)) -> 'a stream end; (* One CORRECT Stream implementation *) structure Stream :> STREAM = struct datatype 'a stream = Cons of ('a * 'a stream) Thunk.thunk fun make (init : 'a, f : 'a -> 'a) : 'a stream = Cons(Thunk.make(fn () => (init, make (f init, f)))) fun make2(init: 'b, f: 'b -> 'a*'b): 'a stream = Cons(Thunk.make(fn() => let val (next_elem, next_state) = f(init) in (next_elem, make2(next_state, f)) end)) fun next (Cons(th) : 'a stream) : 'a * 'a stream = Thunk.apply th end