@@ -50,19 +50,24 @@ cons' = S . lazy
50 iterate f x = S.cons x (S.cons (f x) (S.cons (f (f x)) ...))
50 iterate f x = S.cons x (S.cons (f x) (S.cons (f (f x)) ...))
52iterate : (a -> a) -> a -> Stream a
52iterate : (a -> a) -> a -> Stream a
53−iterate f x = cons' <| \() ->
53+iterate f x = let go = cons' <| \() ->
54− (x, map f (iterate f x))
54+ (x, map f go)
56{-| Create an infinite Stream of xs. -}
57{-| Create an infinite Stream of xs. -}
57repeat : a -> Stream a
58repeat : a -> Stream a
58−repeat x = iterate id x
59+repeat x = let go = cons x <| \() -> go
60{-| Cycle through the elements of the nonempty list (x :: xs) -}
62{-| Cycle through the elements of the nonempty list (x :: xs) -}
61cycle : a -> [a] -> Stream a
63cycle : a -> [a] -> Stream a
62cycle x xs = let cycle' ys = case ys of
64cycle x xs = let cycle' ys = case ys of
63− [] -> cons' <| \() ->
66+ (y :: ys) -> cons y <| \() ->
64− (x, cycle' xs)
69+ (x, cycle' xs)
65− in cycle' []
70+ in go
67{-| Apply a function to every element of a Stream. -}
72{-| Apply a function to every element of a Stream. -}
68map : (a -> b) -> Stream a -> Stream b
73map : (a -> b) -> Stream a -> Stream b