/
BoolLike.lhs
129 lines (77 loc) · 1.56 KB
/
BoolLike.lhs
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
%include polycode.fmt
%include code.fmt
%if style == newcode
> {-# OPTIONS_GHC -F -pgmF lhs2TeX -optF --pre #-}
> module BoolLike where
> import Expr
%endif
\begin{frame}
%if style /= newcode
> (==) :: Eq a => a -> a -> Bool
\pause
> (==) :: (Eq a, BoolLike b) => a -> a -> b
%endif
\end{frame}
\begin{frame}
> class BoolLike b where
> false :: b
> true :: b
> bool :: a -> a -> b -> a
\pause
%if style /= newcode
\begin{overlayarea}{\textwidth}{0.3\textheight}
\only<2>{
> instance BoolLike Bool where
> false = False
> true = True
> bool x y b = if b then y else x
}
\only<3>{
> instance BoolLike Expr where
> false = ConFalse
> true = ConTrue
> bool x y b = If b y x
}
\end{overlayarea}
%endif
\end{frame}
\begin{frame}
%if style /= newcode
> (&&) :: Bool -> Bool -> Bool
> (||) :: Bool -> Bool -> Bool
> not :: Bool -> Bool
\pause
\begin{overlayarea}{\textwidth}{0.5\textheight}
\only<2>{
> (&&) :: BoolLike b => b -> b -> b
> WhiteSpace
> (||) :: BoolLike b => b -> b -> b
> WhiteSpace
> not :: BoolLike b => b -> b
> WhiteSpace
}
\only<3>{
> (&&) :: BoolLike b => b -> b -> b
> (&&) x y = bool x y x
> (||) :: BoolLike b => b -> b -> b
> (||) x y = bool y x x
> not :: BoolLike b => b -> b
> not x = bool true false x
}
\end{overlayarea}
%endif
\end{frame}
\begin{frame}
%if style /= newcode
\textcolor{cmnt}{
\begin{verbatim}
ghci> :t not
not :: (BoolLike b) => b -> b
ghci> not True
False
ghci> not ConTrue
If ConTrue ConFalse ConTrue
\end{verbatim}
}
%endif
\end{frame}