@@ -51,18 +51,22 @@ cons' = S . lazy
5151-}
5252iterate : (a -> a) -> a -> Stream a
5353iterate f x = cons' <| \() ->
54− (x, map f (iterate f x))
54+ (x, iterate f (f x))
5555
5656{-| Create an infinite Stream of xs. -}
5757repeat : a -> Stream a
58−repeat x = iterate id x
58+repeat x = let go = cons x <| \() -> go
59+ in go
5960
6061{-| Cycle through the elements of the nonempty list (x :: xs) -}
6162cycle : a -> [a] -> Stream a
6263cycle x xs = let cycle' ys = case ys of
63− [] -> cons' <| \() ->
64− (x, cycle' xs)
65− in cycle' []
64+ [] -> go
65+ (y :: ys) -> cons y <| \() ->
66+ cycle' ys
67+ go = cons' <| \() ->
68+ (x, cycle' xs)
69+ in go
6670
6771{-| Apply a function to every element of a Stream. -}
6872map : (a -> b) -> Stream a -> Stream b