We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fd3a38e commit 395a9b1Copy full SHA for 395a9b1
part1_chapter7_exercise6/Main.hs
@@ -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