summaryrefslogtreecommitdiff
path: root/lec06
diff options
context:
space:
mode:
Diffstat (limited to 'lec06')
-rw-r--r--lec06/Fibonacci.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/lec06/Fibonacci.hs b/lec06/Fibonacci.hs
index 70d8934..2b6e343 100644
--- a/lec06/Fibonacci.hs
+++ b/lec06/Fibonacci.hs
@@ -23,3 +23,14 @@ streamToList (Cons a s) = a : streamToList s
instance Show a => Show (Stream a) where
show s = show $ take 20 $ streamToList s
+-- Exercise 4
+
+streamRepeat :: a -> Stream a
+streamRepeat e = Cons e (streamRepeat e)
+
+streamMap :: (a -> b) -> Stream a -> Stream b
+streamMap f (Cons a as) = Cons (f a) (streamMap f as)
+
+streamFromSeed :: (a -> a) -> a -> Stream a
+streamFromSeed f s = Cons s (streamFromSeed f (f s))
+