@@ -50,19 +50,24 @@ cons' = S . lazy
5050 iterate f x = S.cons x (S.cons (f x) (S.cons (f (f x)) ...))
5151-}
5252iterate : (a -> a) -> a -> Stream a
53−iterate f x = cons' <| \() ->
54− (x, map f (iterate f x))
53+iterate f x = let go = cons' <| \() ->
54+ (x, map f go)
55+ in go
5556
5657{-| Create an infinite Stream of xs. -}
5758repeat : a -> Stream a
58−repeat x = iterate id x
59+repeat x = let go = cons x <| \() -> go
60+ in go
5961
6062{-| Cycle through the elements of the nonempty list (x :: xs) -}
6163cycle : a -> [a] -> Stream a
6264cycle x xs = let cycle' ys = case ys of
63− [] -> cons' <| \() ->
64− (x, cycle' xs)
65− in cycle' []
65+ [] -> go
66+ (y :: ys) -> cons y <| \() ->
67+ cycle' ys
68+ go = cons' <| \() ->
69+ (x, cycle' xs)
70+ in go
6671
6772{-| Apply a function to every element of a Stream. -}
6873map : (a -> b) -> Stream a -> Stream b