(* twins.sml *) (* twins stream transformer *) structure Twins :> TWINS = struct fun twins stm = let val init : int * int Stream.stream = Stream.get stm fun next (n, stm) = let val (m, stm) = Stream.get stm in if m = n + 2 then ((n, m), (m, stm)) else next (m, stm) end in Stream.make(init, next) end end;