-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapterSeven.hs
43 lines (34 loc) · 940 Bytes
/
chapterSeven.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module ChapterSeven where
add :: Int -> Int -> Int
add x y = x + y
addPF :: Int -> Int -> Int
addPF = (+)
addOne :: Int -> Int
addOne x = x + 1
addOnePF :: Int -> Int
addOnePF = (+1)
hundredthDigit :: Integral a => a -> a
hundredthDigit x = d
where onesD = x `div` 100
d = onesD `mod` 10
tensDigitDivMod :: Integral a => a -> a
tensDigitDivMod x = mod (fst (divMod x 10)) 10
foldBool :: a -> a -> Bool -> a
foldBool x y z
| z = x
| otherwise = y
g :: (a -> b) -> (a, c) -> (b, c)
g f (x, y) = (f x, y)
main :: IO ()
main = do
print (0 :: Int)
print (add 1 0)
print (addOne 0)
print (addOnePF 0)
print ((addOne . addOne) 0)
print ((addOnePF . addOne) 0)
print ((addOne . addOnePF) 0)
print ((addOnePF . addOnePF) 0)
print (negate (addOne 0))
print ((negate . addOne) 0)
print ((addOne . addOne . addOne . negate . addOne) 0)