Skip to content

Commit 243654a

Browse files
committed
[exercise] 7.6
1 parent 2a00a30 commit 243654a

File tree

1 file changed

+16
-0
lines changed
  • chapter07-High-order-functions

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)