@@ -1,12 +1,10 @@
1+module Lazy ( run, thunk
4−{-| Library for efficient Lazy evaluation and Infinite Streams.
4+{-| Library for efficient Lazy evaluation.
9−import Signal ((<~), foldp, Signal)
10import Native.Lazy
8import Native.Lazy
12data Lazy a = L { run : () -> a }
10data Lazy a = L { run : () -> a }
@@ -16,47 +14,5 @@ thunk : (() -> a) -> Lazy a
16thunk t = L { run = (Native.Lazy.thunk t) }
14thunk t = L { run = (Native.Lazy.thunk t) }
18run : Lazy a -> a
16run : Lazy a -> a
19−run l = case l of L r -> r.run ()
17+run (L r) = r.run ()
21−data Stream a = S { hd : a, tl : Lazy (Stream a) }
26−tl : Stream a -> Stream a
29−repeat : a -> Stream a
30−repeat x = S { hd = x, tl = thunk (\() -> repeat x) }
32−cycle : a -> [a] -> Stream a
33−cycle x xs = let cycle' ys = case ys of
34− [] -> S { hd = x, tl = thunk (\() -> cycle' xs) }
35− (y :: ys) -> S { hd = y, tl = thunk (\() -> cycle' ys) }
38−map : (a -> b) -> Stream a -> Stream b
39−map f xs = S { hd = f (hd xs)
40− , tl = thunk (\() -> map f (tl xs))
43−zip : Stream a -> Stream b -> Stream (a, b)
44−zip = zipWith (\x y -> (x,y))
46−zipWith : (a -> b -> c) -> Stream a -> Stream b -> Stream c
47−zipWith f xs ys = S { hd = f (hd xs) (hd ys)
48− , tl = thunk (\() -> zipWith f (tl xs) (tl ys)) }
50−take : Int -> Stream a -> [a]
53− n -> hd xs :: take (n - 1) (tl xs)
55−iterate : (a -> a) -> a -> Stream a
56−iterate f x = S { hd = x
57− , tl = thunk (\() -> map f (iterate f x))
60−observeWhen : Stream a -> Signal b -> Signal a
61−observeWhen str sig = let tls = foldp (\_ -> tl) str sig in