@@ -1,10 +1,52 @@
1module Prelude.Stream
1module Prelude.Stream
3import Prelude.Vect
4import Prelude.Vect
5codata Stream : Type -> Type where
9codata Stream : Type -> Type where
6 (::) : a -> Stream a -> Stream a
10 (::) : a -> Stream a -> Stream a
12+instance Functor Stream where
13+ map f (x::xs) = f x :: map f xs
18+tail : Stream a -> Stream a
8take : (n : Nat) -> Stream a -> Vect n a
21take : (n : Nat) -> Stream a -> Vect n a
9take Z _ = []
22take Z _ = []
10take (S n) (x :: xs) = x :: (take n xs)
23take (S n) (x :: xs) = x :: (take n xs)
26+drop : Nat -> Stream a -> Stream a
28+drop (S k) (x::xs) = drop k xs
30+repeat : a -> Stream a
31+repeat x = x :: repeat x
33+iterate : (a -> a) -> a -> Stream a
34+iterate f x = x :: iterate f (f x)
36+index : Nat -> Stream a -> a
38+index (S k) (x::xs) = index k xs
40+zipWith : (a -> b -> c) -> Stream a -> Stream b -> Stream c
41+zipWith f (x::xs) (y::ys) = f x y :: zipWith f xs ys
43+zip : Stream a -> Stream b -> Stream (a, b)
44+zip = zipWith (\x,y => (x,y))
46+unzip : Stream (a, b) -> (Stream a, Stream b)
47+unzip xs = (map fst xs, map snd xs)
49+diag : Stream (Stream a) -> Stream a
50+diag ((x::xs)::xss) = x :: diag (map tail xss)