-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotawat.tex
233 lines (181 loc) · 3.88 KB
/
notawat.tex
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
\documentclass{beamer}
\usetheme{default}
\title{The Not-A-Wat in Haskell}
\author{Brian Hurt}
\date{18 Oct 2015}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\begin{center}{\tt \Huge <RANT>}\end{center}
\end{frame}
\begin{frame}
\frametitle{Wat Definition}
\begin{center}\Large{What is a "Wat"?}\end{center}
\end{frame}
\begin{frame}
\frametitle{Wat Definition}
\begin{center}\Large{https://www.destroyallsoftware.com/talks/wat}\end{center}
\end{frame}
\begin{frame}
\frametitle{Wat Definition}
\begin{center}
My definition:
A "wat" (w.r.t. programming languages) is a behavior that is both
unexpected, and inconsistent with all the other behaviors of the
language.
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{The Wat In Question}
{\tt \Large{
Prelude> length (1, 2)\\
}}
\end{frame}
\begin{frame}[fragile]
\frametitle{The Wat In Question}
{\tt \Large{
Prelude> length (1, 2)\\
1\\
Prelude>
}}
\end{frame}
\begin{frame}
\frametitle{Wat Definition}
\begin{center}
{\Huge This is not a Wat!}
This behavior is consitent with the rest of the language.
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{Working Through the Logic}
{\Large
Length gives the number of elements held by a container.
\vspace{20pt}
{\tt
Prelude> length [ 1, 2, 3 ]\\
3\\
Prelude>
}
\vspace{20pt}
Length just folds over the container, counting the elements as they go by.
}
\end{frame}
\begin{frame}
\frametitle{Working Through the Logic}
\begin{center}
{\Large
Can you have a container that can \textsl{not} hold an arbitrary number
of elements, but can only hold at most one?
}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{Working Through the Logic}
{\Large
{\tt Maybe} works as a "at most one" container:
\vspace{20pt}
{\tt
Prelude> length Nothing\\
0\\
Prelude> length (Just "foo")\\
1\\
Prelude> fmap show Nothing\\
Nothing\\
Prelude> fmap show (Just 1)\\
Just "1"\\
}}
\end{frame}
\begin{frame}
\frametitle{Working Through the Logic}
{\Large
You can partially apply multi-param types just like functions.
So {\tt Either String } works as a "at most one" container:
{\tt Prelude> foldr (+) 0 (Left "foo") \\
0 \\
Prelude> foldr (+) 0 (Right 2) \\
2 \\
Prelude> fmap show (Right 3) \\
Right "3" \\
Prelude> \\
}}
\end{frame}
\begin{frame}[fragile]
\frametitle{Working Through the Logic}
{\Large
It is foldable, there for length is defined on it:
\vspace{32pt}
{\tt
Prelude> :t length \\
length :: Foldable t => t a -> Int \\
Prelude> length (Left "error message") \\
0 \\
Prelude> length (Right 1) \\
1 \\
Prelude>
}}
\end{frame}
\begin{frame}
\frametitle{Important Concept}
\begin{center}
\textbf{\Huge Tuples}
\vspace{20pt}
\textbf{\Huge Are}
\vspace{20pt}
\textbf{\Huge Not}
\vspace{20pt}
\textbf{\Huge Lists}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Important Concept}
{\Large
\begin{itemize}
\item {\tt (,)} is a type, \textbf{just like Either}
\item {\tt (,)} takes two type parameters, \textbf{just like Either}
\item {\tt (,)} as a type can be partially applied, \textbf{just like Either}
\end{itemize}
\vspace{20pt}
So, if we apply {\tt (,)} to one type (like we do with Either), what do we get?
}
\end{frame}
\begin{frame}
\frametitle{Important Concept}
\begin{center}
{\Large
We get a container that holds exactly one value, as the second value of the tuple.
}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{Tuples are a Container}
{\Large
{\tt
Prelude> foldr (+) 0 (1, 2) \\
2 \\
Prelude> foldr (+) 0 ("foo", 2) \\
2 \\
Prelude> fmap show (1, 2) \\
(1,"2") \\
Prelude> fmap show (False, 2) \\
(False,"2") \\
Prelude> length (False, 2) \\
1 \\
Prelude> \\
}}
\end{frame}
\begin{frame}
\frametitle{Tuples are a Container}
\begin{center}
What value did you expect {\tt length} to return?
\vspace{32pt}
nil?
\vspace{32pt}
NaN?
\end{center}
\end{frame}
\begin{frame}
\begin{center}\tt \Huge{</RANT>}\end{center}
\end{frame}
\end{document}