-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttg.tex
190 lines (168 loc) · 3.73 KB
/
ttg.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
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
\begin{lstlisting}[style=haskell]
data ICE =
ICE
AirInduction
FuelInduction
Ignition
ICEType
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
but we came prepared with Trees That (will probably) Grow
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
\begin{lstlisting}[style=haskell]
type family XICE x
data ICE_ x =
ICE_
AirInduction
FuelInduction
Ignition
ICEType
(XICE x)
type instance XICE () = ()
type ICE = ICE_ ()
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
pattern-matching becomes a pain in the undecorated case:
\begin{lstlisting}[style=haskell]
case ice of
ICE_ air fuel ign typ () ->
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
so we write a pattern-synonym:
\begin{lstlisting}[style=haskell]
pattern ICE air fuel ign typ <-
ICE_ air fuel ign typ _
where ICE air fuel ign typ =
ICE_ air fuel ign typ ()
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
using the pattern-synonym:
\begin{lstlisting}[style=haskell]
case ice of
ICE air fuel ign typ ->
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
We can add an image to \lstinline{data ICE_}
\begin{lstlisting}[style=haskell]
type instance XICE Image = Image
type ICE_Image = ICE Image
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
We can also add fields to sum types:
\begin{lstlisting}[style=haskell]
data Either a b =
Left a
| Right b
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
Either that grows
\begin{lstlisting}[style=haskell]
type family XEither x
data Either_ x a b =
Left_ a (XEither x)
| Right_ b (XEither x)
type instance XEither () = ()
type Either = Either_ ()
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
and add pattern-synonyms:
\begin{lstlisting}[style=haskell]
pattern Left a <- Left_ a _
where Left a = Left_ a ()
pattern Right a <- Right_ a _
where Right a = Right_ a ()
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
Note that there exists
\begin{lstlisting}[style=haskell]
xeither :: Lens (Either_ x a b) (XEither x)
\end{lstlisting}
\begin{lstlisting}[style=haskell]
data Either_ x a b =
Left_ a (XEither x)
| Right_ b (XEither x)
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
We can add constructors to sum types:
\begin{lstlisting}[style=haskell]
data These a b =
This a
| That b
| Both a b
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
Theses that grow
\begin{lstlisting}[style=haskell]
type family XThese x
data These_ x a b =
This_ a
| That_ b
| Both_ a b
| XThese_ (XThese x)
type instance XThese Void = Void
type These = These_ Void
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
We could add pattern-synonyms, like before
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow}
We could also write the prisms
\begin{lstlisting}[style=haskell]
_This :: Prism (These_ x a b) a
_That :: Prism (These_ x a b) b
_Both :: Prism (These_ x a b) (a, b)
_XThese :: Prism (These_ x a b) (XThese x)
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Trees That Grow extends to:\cite{najd2016trees}}
\begin{itemize}
\item existential types
\item GADTs
\end{itemize}
\end{block}
\end{frame}