-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTalk.tex
259 lines (216 loc) · 6.76 KB
/
Talk.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
\documentclass[tikz, 12pt]{beamer}
% for themes, etc.
\mode<presentation>
{ \usetheme{Copenhagen}
\usecolortheme{seahorse}{}
\usefonttheme{professionalfonts}
}
\setbeamertemplate{itemize items}[default]
\setbeamertemplate{enumerate items}[default]
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{headline}{}
\setbeamertemplate{footline}{}
\usepackage{times} % fonts are up to you
\usepackage{proof}
\usepackage{listings}
\usepackage{courier}
\usepackage{graphicx}
\usepackage{stmaryrd}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,double,inner sep=1pt] (char) {#1};}}
\DeclareMathOperator{\Wtype}{W}
\DeclareMathOperator{\Mtype}{M}
\DeclareMathAlphabet{\mathbfsf}{\encodingdefault}{\sfdefault}{sb}{n}
\def\Type{\mathbfsf{Type}}
\lstset{columns=fullflexible}
\lstset{
literate={->}{$\to$ }{1}
{(->)}{$(\to)$ }{1}
{=>}{$\Rightarrow$ }{1}
{<-:}{$\Mapsfrom$ }{1}
{(<-:)}{($\Mapsfrom$)}{1}
{:E}{$\in$ }{1}
{:<}{$\subseteq$ }{1}
{forall}{$\forall$}{1}
{(<+>)}{($\oplus$) }{1}
{<+>}{$\oplus$ }{1}
{<<*>>}{$\circled{$\star$}$ }{1}
{<<map>>}{$\circled{\$}$ }{1}
{(<<map>>)}{($\circled{\$}$) }{1}
{(<<*>>)}{($\circled{$\star$}$) }{1}
{Nat}{$\mathbb{N}$}{1}
{Int}{$\mathbb{Z}$}{1},
escapeinside=||,
moredelim=**[is][\color{red}]{@}{@},
}
\lstset{language=Haskell}
% these will be used later in the title page
\title{Introduction to Vinyl}
\author{Jon Sterling\\
jonmsterling.com
}
\begin{document}
% this prints title, author etc. info from above
\begin{frame}
\titlepage
\end{frame}
\section{Extensible Records and Row Polymorphism}
\begin{frame}[fragile]
\frametitle{Records in GHC 7.8}\pause
\begin{itemize}
\item Haskell records are nominally typed\pause
\item They may not share field names
\end{itemize}
\pause
\begin{lstlisting}
data R = R { x :: X } |\pause|
data R' = R' { x :: X } -- ^ Error
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Structural Typing}\pause
\begin{itemize}
\item Sharing field names and accessors\pause
\item Record types may be characterized \emph{structurally}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Row Polymorphism}\pause
How do we express the type of a function which adds a field to a record?\pause
\only<3>{
\[
\infer{ f(x) : \{foo:A, bar:B\} }{ x : \{foo:A\} }
\]
}
\only<4>{
\[
\infer{ f(x) : \{foo:A, bar:B; \vec{rs}\} }{ x : \{foo:A; \vec{rs}\} }
\]
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Roll Your Own in Haskell}\pause
\begin{lstlisting}
data (s :: Symbol) ::: (t :: *) = Field |\pause|
data Rec :: [*] -> * where |\pause|
RNil :: Rec '[] |\pause|
(:&) :: !t -> !(Rec rs) -> Rec ((s ::: t) ': rs)
|\pause|
class s :E (rs :: [*])|\pause|
class ss :< (rs :: [*]) where
cast :: Rec rs -> Rec ss|\pause|
(=:) : s ::: t -> t -> Rec '[s ::: t]|\pause|
(<+>) : Rec ss -> Rec ts -> Rec (ss ++ ts)|\pause|
lens : s ::: t :E rs => s ::: t -> Lens' (Rec rs) t
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Roll Your Own in Haskell}\pause
\begin{lstlisting}
f :: Rec ("foo" ::: A ': rs)
-> Rec ("bar" ::: B ': "foo" ::: A ': rs)
\end{lstlisting}
\end{frame}
\section{Universes \`a la Tarski}
\begin{frame}
\frametitle{Universes \`a la Tarski}\pause
\begin{itemize}
\item A type $\mathcal{U}$ of \textbf{codes} for types.
\pause
\item Function $El_\mathcal{U} : \mathcal{U}\to\Type$.
\pause
\[
\infer{
\Gamma\vdash El_\mathcal{U}(s) : \Type
}{
\Gamma\vdash s : \mathcal{U}
}
\]
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Universes \`a la Tarski}
\begin{center}
\includegraphics[width=2.8in]{universe-empty.pdf}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Universes \`a la Tarski}
\begin{center}
\includegraphics[width=2.8in]{universe-embedded.pdf}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Universes \`a la Tarski}
\begin{center}
\includegraphics[width=2.8in]{universe-populated.pdf}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Universes \`a la Tarski}
\begin{center}
\includegraphics[width=2.8in]{universe-interpretation.pdf}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{Records in Haskell}\pause
\begin{lstlisting}
data Rec :: (|$\mathcal{U}$| -> *) -> [ |$\mathcal{U}$| ] -> * where |\pause|
RNil :: Rec el|$_\mathcal{U}$| '[] |\pause|
(:&) :: !(el|$_\mathcal{U}$| r) -> !(Rec el|$_\mathcal{U}$| rs) -> Rec el|$_\mathcal{U}$| (r ': rs)
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Records in Haskell (Actually)}\pause
\begin{lstlisting}
data TyFun :: * -> * -> *|\pause|
type family (f :: TyFun k l -> *) $ (x :: k) :: l|\pause|
data Rec :: (TyFun |$\mathcal{U}$| * -> *) -> [ |$\mathcal{U}$| ] -> * where
RNil :: Rec el|$_\mathcal{U}$| '[]
(:&) :: !(el|$_\mathcal{U}$| $ r) -> !(Rec el|$_\mathcal{U}$| rs) -> Rec el|$_\mathcal{U}$| (r ': rs)
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Recovering HList}\pause
\begin{lstlisting}
data Id :: (TyFun k k) -> * where
type instance Id $ x = x|\pause|
type HList rs = Rec Id rs|\pause|
ex :: HList [Int, Bool, String] |\pause|
ex = 34 :& True :& "vinyl" :& RNil
\end{lstlisting}
\end{frame}
\section{Effectful Records}
\begin{frame}[fragile]
\frametitle{Effects inside records}
\begin{lstlisting}
data Rec :: (TyFun |$\mathcal{U}$| * -> *) -> (* -> *) -> [ |$\mathcal{U}$| ] -> * where
RNil :: Rec el|$_\mathcal{U}$| f '[]
(:&) :: !(f (el|$_\mathcal{U}$| $ r)) -> !(Rec el|$_\mathcal{U}$| f rs) -> Rec el|$_\mathcal{U}$| f (r ': rs)|\pause|
(=:) : Applicative f => sing r -> el|$_\mathcal{U}$| $ r -> Rec el|$_\mathcal{U}$| f '[r]|\pause|
k =: x = pure x :& RNil|\pause|
(<-:) : sing r -> f (el|$_\mathcal{U}$| $ r) -> Rec el|$_\mathcal{U}$| f '[r]|\pause|
k <-: x = x :& RNil
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Compositional Kit}\pause
\begin{lstlisting}
newtype Lift o f g x = Lift { runLift :: f x `o` g x }|\pause|
type Validator = Lift (->) Identity (Either Error)|\pause|
type JSONRenderer = Lift (->) Identity (Const Aeson.Pair)|\pause|
(<<*>>) :: Rec|$_\mathcal{U}$| (Lift (->) f g) rs -> Rec|$_\mathcal{U}$| f rs -> Rec|$_\mathcal{U}$| g rs|\pause|
rdist :: Applicative f => Rec|$_\mathcal{U}$| f rs -> f (Rec|$_\mathcal{U}$| Identity rs)|\pause|
rtraverse ::
Applicative h
=> (f |$\leadsto$| h |$\circ$| g)
-> Rec|$_\mathcal{U}$| f rs
-> h (Rec|$_\mathcal{U}$| g rs)
\end{lstlisting}
\end{frame}
\begin{frame}
\centerline{\emph{\textbf{Demonstration}}}
\end{frame}
\end{document}