summaryrefslogtreecommitdiff
path: root/lec06
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-26 16:45:18 +0200
committerEdoardo La Greca2025-08-26 16:45:18 +0200
commit8076d92345884143ce50a942c301255e954c34c4 (patch)
tree5fa3cf1fc540a1244e2eff202f16d575d4dbbce2 /lec06
parent420960b427f7106c92ced4c86e7d7b9ebf52fb76 (diff)
add fourth exercise of lecture 6
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))
+