-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlec1-types.tex
More file actions
206 lines (186 loc) · 4.88 KB
/
lec1-types.tex
File metadata and controls
206 lines (186 loc) · 4.88 KB
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
\documentclass{notes}
\coursename{Logical Relations Mini-Course}
\lecnumber{1}
\title{Type System Fundamentals}
\author{Michael Piskozub}
\begin{document}
\maketitle
\newcommand{\proves}{\vdash}
\newcommand{\fst}[1]{\textsf{fst} \: #1}
\newcommand{\snd}[1]{\textsf{snd} \: #1}
\newcommand{\inl}[1]{\textsf{inl} \: #1}
\newcommand{\inr}[1]{\textsf{inr} \: #1}
\newcommand{\case}[3]{\textsf{case} \: (#1, x . #2, y . #3)}
\newcommand{\unit}{()}
\newcommand{\matchdone}[1]{\textsf{match} \: #1 \: \textsf{done}}
\newcommand{\betaequiv}{\equiv_{\beta}}
\newcommand{\etaequiv}{\equiv_{\eta}}
% \newcommand{\RuleTemplate}[5]{
% \ensuremath{%
% \infer[#1]{#3}{#4}%
% \if\relax\detokenize{#1}\relax
% \infer{#3}{#4}
% \else
% {\textsc{\rulefiguresize[#1]}}~\infer{#3}{#4}
% \fi%
% }%
% \if\relax\detokenize{#2}\relax\else\label{#2}\fi%
% \if\relax\detokenize{#5}\relax\else~\text{#5}\fi
% }
% \newcommand{\Rule}[4][]{%
% \if\relax\detokenize{#2}\relax
% \RuleTemplate{}{}{#3}{#4}{#1}
% \else
% \RuleTemplate{#2}{rule:#2}{#3}{#4}{#1}
% \fi}
% \newcommand{\NlRule}[4][]{\RuleTemplate{#2}{}{#3}{#4}{#1}}
\begin{syntax}
\category[Expressions]{e}
% Each alternative is introduced on its own line.
\alternative{x}
\alternative{\lambda x . e}
\alternative{e_1 e_2}
\alternative{(e_1, e_2)}
\alternative{\fst e}
\alternative{\snd e}
\alternative{\inl e}
\alternative{\inr e}
\alternative{\case{e_1}{e_2}{e_3}}
\alternative{\unit}
\alternative{\matchdone e}
\end{syntax}
\vspace{0.3in}
\bf{Typing Rules:}
\begin{mathpar}
\infer[Axiom]{x : \tau \in \Gamma}{\Gamma \proves x : \tau}
\and
\infer[$\to$-I]{
\Gamma, x : \tau \proves e : \sigma
}{
\Gamma \proves \lambda x . e : \tau \rightarrow \sigma
}
\and
\infer[$\to$-E]{
\Gamma \proves e_1 : \tau \rightarrow \sigma \\ \Gamma \proves e_2 : \tau
}{
\Gamma \proves e_1 e_2 : \sigma
}
\and
\\
\infer[$\times$-I]{
\Gamma \proves e_1 : \tau
\\
\Gamma \proves e_2 : \sigma
}{
\Gamma \proves (e_1, e_2) : \tau \times \sigma
}
\and
\infer[$\times$-E1]{
\Gamma \proves e : \tau \times \sigma
}{
\Gamma \proves \fst{e} : \tau
}
\and
\infer[$\times$-E2]{
\Gamma \proves e : \tau \times \sigma
}{
\Gamma \proves \snd{e} : \sigma
}
\and
\\
\infer[$+$-I1]{
\Gamma \proves e : \tau
}{
\Gamma \proves \inl{e} : \tau + \sigma
}
\and
\infer[$+$-I2]{
\Gamma \proves e : \sigma
}{
\Gamma \proves \inr{e} : \tau + \sigma
}
\and
\infer[$+$-E]{
\Gamma \proves e_1 : \tau + \sigma
\\
\Gamma, x : \tau \proves e_2 : \rho
\\
\Gamma, y : \sigma \proves e_3 : \rho
}{
\Gamma \proves \case{e_1}{e_2}{e_3} : \rho
}
\and
\\
\infer[\textsf{unit}-I]{ }{
\Gamma \proves \unit : unit
}
\and
\infer[\textsf{void}-E]{
\Gamma \proves e : void
}{
\Gamma \proves \matchdone{e} : \tau
}
\end{mathpar}
\begin{nb}
There is a duality of types here. Products are duals of coproducts and $void$ is
the dual of $unit$. For any dual types, the introduction forms of one correspond
to the elimination forms of the other, and vice versa.
\end{nb}
\vspace{0.3in}
\bf{$\beta$ and $\eta$ Equivalence:}
\begin{nb}
$\beta$ and $\eta$ equivalences come directly from introduction and
elimination rules.
\\
$\beta$ equivalence: Apply elimination directly to an introduction form.
\\
$\eta$ equivalence: Apply introduction directly to an elimination form.
\end{nb}
\begin{mathpar}
(\lambda x . e_1) e_2 \betaequiv e_1[x \mapsto e_2]
\and
f \etaequiv \lambda x . (f \: x)
\and
\\
\fst (e_1, e_2) \betaequiv e_1
\and
\snd (e_1, e_2) \betaequiv e_2
\and
(\fst{e}, \snd{e}) \etaequiv e
\end{mathpar}
\begin{nb}
Since product types have two elimination rules, there are two $\beta$ equivalences.
Likewise, since product types have one introduction rule, there is one $\eta$ rule.
\end{nb}
\begin{mathpar}
\case{\inl{e_1}}{e_2}{e_3} \betaequiv e_2[x \mapsto e_1]
\and
\case{\inr{e_1}}{e_2}{e_3} \betaequiv e_3[y \mapsto e_1]
\and
\\
\case{e_1}{\inl{x}}{\inr{y}} \etaequiv e_1
\end{mathpar}
\begin{nb}
Note that the continuation of a case expression is $embedded$ in the case
expression. So, the introduction rules must be embedded in the continuations
of the case expression in the $\eta$ equivalence.
\end{nb}
\begin{mathpar}
e \etaequiv \unit
\and
\text{C}[\matchdone{e}] \betaequiv \matchdone{e}
\end{mathpar}
\begin{nb}
The $\eta$ rule says that if you have $e : unit$, then that it is $\eta$
equivalent to the introduction form.
\\
In the $\beta$ rule, $\bf{C}[.]$ is an evaluation context. Something of type
$void$ cannot be built, so if there is an expression $e : void$ in your
computation, we can skip the entire computation and just give back
$\bf{match}$ $e$ $\bf{done}$.
\end{nb}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: