-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchapter-09.hs
96 lines (41 loc) · 920 Bytes
/
chapter-09.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
-- Exercise 9.1
fact :: Integer -> Integer
fact n
| n == 0 = 1
| otherwise = n * fact (n - 1)
{-
ghci> (4 > 2) || (fact (-1) == 17)
True -- Because of laziness, fact never gets called.
ghci> (4 > 2) && (fact (-1) == 17)
-- hangs forever because fact (-1) isn't handled well.
-}
-- Exercise 9.2
mult :: Integer -> Integer -> Integer
mult x y
| x == 0 = 0
| otherwise = x * y
{-
ghci> mult 0 (fact (-2))
0 -- again, being lazy, the call to fact is never done
-}
-- Exercise 9.3
{-
Proof that
A flipV (flipH pic) = flipH (flipV pic)
B flipV (flipV pic) = pic
C flipH (flipH pic) = pic
Proof of A
==========
-}
-- Exercise 9.4
-- Exercise 9.5
-- Exercise 9.6
-- Exercise 9.7
-- Exercise 9.8
-- Exercise 9.9
-- Exercise 9.10
-- Exercise 9.11
-- Exercise 9.12
-- Exercise 9.13
-- Exercise 9.14
-- Exercise 9.15