There was an error while loading. Please reload this page.
1 parent 2a00a30 commit 243654aCopy full SHA for 243654a
chapter07-High-order-functions/6.hs
@@ -0,0 +1,16 @@
1
+import Data.Char
2
+
3
+type Bit = Int
4
5
+unfold :: (a -> Bool) -> (a -> b) -> (a -> a) -> a -> [b]
6
+unfold p h t x | p x = []
7
+ | otherwise = h x : unfold p h t (t x)
8
9
+chop8 :: [Bit] -> [[Bit]]
10
+chop8 = unfold null (take 8) (drop 8)
11
12
+map :: (a -> b) -> [a] -> [b]
13
+map f = unfold null (f . head) tail
14
15
+iterate :: (a -> a) -> a -> [a]
16
+iterate f = unfold (const True) id f
0 commit comments