Skip to content

Commit 395a9b1

Browse files
committed
Part 1 Chapter 7 Exercise 6 - part 1.
1 parent fd3a38e commit 395a9b1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

part1_chapter7_exercise6/Main.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- option 1 (https://github.com/PiotrJustyna/haskell-anywhere):
2+
-- ./ghci.bat C:\Users\piotr_justyna\Documents\github\programming-in-haskell\part1_chapter7_exercise6
3+
-- option 2 (stack):
4+
-- stack ghci
5+
-- option 3 (ghci):
6+
-- ghci
7+
--
8+
-- :load Main
9+
main = do
10+
putStrLn "int2bin 9"
11+
putStrLn . show $ int2bin 9
12+
13+
unfold :: (a -> Bool) -> (a -> a) -> (a -> a) -> a -> [a]
14+
unfold predicate headFunction tailFunction x
15+
| predicate x = []
16+
| otherwise = headFunction x : unfold predicate headFunction tailFunction (tailFunction x)
17+
18+
int2bin = unfold (== 0) (`mod` 2) (`div` 2)

0 commit comments

Comments
 (0)