2 \usepackage[sc,slantedGreek]{mathpazo}
5 % Comment these out if you don't want a slide with just the
6 % part/section/subsection/subsubsection title:
7 \AtBeginPart{\frame{\partpage}}
8 \AtBeginSection{\frame{\sectionpage}}
9 \AtBeginSubsection{\frame{\subsectionpage}}
10 \AtBeginSubsubsection{\frame{\subsubsectionpage}}
11 \beamertemplatenavigationsymbolsempty
13 \setlength{\parindent}{0pt}
14 \setlength{\parskip}{6pt plus 2pt minus 1pt}
15 \setlength{\emergencystretch}{3em} % prevent overfull lines
16 \setcounter{secnumdepth}{0}
18 \usepackage[english]{babel}
19 \usepackage[conor]{agda}
20 \renewcommand{\AgdaKeywordFontStyle}[1]{\ensuremath{\mathrm{\underline{#1}}}}
21 \renewcommand{\AgdaFunction}[1]{\textbf{\textcolor{AgdaFunction}{#1}}}
22 \renewcommand{\AgdaField}{\AgdaFunction}
23 % \definecolor{AgdaBound} {HTML}{000000}
24 \definecolor{AgdaHole} {HTML} {FFFF33}
26 \DeclareUnicodeCharacter{9665}{\ensuremath{\lhd}}
27 \DeclareUnicodeCharacter{964}{\ensuremath{\tau}}
28 \DeclareUnicodeCharacter{963}{\ensuremath{\sigma}}
29 \DeclareUnicodeCharacter{915}{\ensuremath{\Gamma}}
30 \DeclareUnicodeCharacter{8799}{\ensuremath{\stackrel{?}{=}}}
31 \DeclareUnicodeCharacter{9655}{\ensuremath{\rhd}}
33 \newcommand{\mysmall}{}
34 \newcommand{\mysyn}{\AgdaKeyword}
35 \newcommand{\mytyc}[1]{\textup{\AgdaDatatype{#1}}}
36 \newcommand{\mydc}[1]{\textup{\AgdaInductiveConstructor{#1}}}
37 \newcommand{\myfld}[1]{\textup{\AgdaField{#1}}}
38 \newcommand{\myfun}[1]{\textup{\AgdaFunction{#1}}}
39 \newcommand{\myb}[1]{\AgdaBound{$#1$}}
40 \newcommand{\myfield}{\AgdaField}
41 \newcommand{\myind}{\AgdaIndent}
42 \newcommand{\mykant}{\textmd{\textsc{Bertus}}}
43 \newcommand{\mysynel}[1]{#1}
44 \newcommand{\myse}{\mysynel}
45 \newcommand{\mytmsyn}{\langle t \rangle}
46 \newcommand{\mysp}{\ }
47 \newcommand{\myabs}[2]{\mydc{$\lambda$} #1 \mathrel{\mydc{$\mapsto$}} #2}
48 \newcommand{\myappsp}{\hspace{0.07cm}}
49 \newcommand{\myapp}[2]{#1 \myappsp #2}
50 \newcommand{\mysynsep}{\ \ |\ \ }
51 \newcommand{\myITE}[3]{\myfun{If}\, #1\, \myfun{Then}\, #2\, \myfun{Else}\, #3}
52 \newcommand{\mycumul}{\preceq}
54 \newcommand{\mydesc}[3]{
60 \hfill \textup{\phantom{ygp}\textbf{#1}} $#2$
61 \framebox[\textwidth]{
76 \newcommand{\mytmt}{\mysynel{t}}
77 \newcommand{\mytmm}{\mysynel{m}}
78 \newcommand{\mytmn}{\mysynel{n}}
79 \newcommand{\myred}{\leadsto}
80 \newcommand{\myredd}{\stackrel{*}{\leadsto}}
81 \newcommand{\myreddd}{\stackrel{*}{\reflectbox{$\leadsto$}}}
82 \newcommand{\mysub}[3]{#1[#3 / #2]}
83 \newcommand{\mytysyn}{\langle ty \rangle}
84 \newcommand{\mybasetys}{K}
85 \newcommand{\mybasety}[1]{B_{#1}}
86 \newcommand{\mytya}{\myse{A}}
87 \newcommand{\mytyb}{\myse{B}}
88 \newcommand{\mytycc}{\myse{C}}
89 \newcommand{\myarr}{\mathrel{\textcolor{AgdaDatatype}{\to}}}
90 \newcommand{\myprod}{\mathrel{\textcolor{AgdaDatatype}{\times}}}
91 \newcommand{\myctx}{\Gamma}
92 \newcommand{\myvalid}[1]{#1 \vdash \underline{\mathrm{valid}}}
93 \newcommand{\myjudd}[3]{#1 \vdash #2 : #3}
94 \newcommand{\myjud}[2]{\myjudd{\myctx}{#1}{#2}}
95 \newcommand{\myabss}[3]{\mydc{$\lambda$} #1 {:} #2 \mathrel{\mydc{$\mapsto$}} #3}
96 \newcommand{\mytt}{\mydc{$\langle\rangle$}}
97 \newcommand{\myunit}{\mytyc{Unit}}
98 \newcommand{\mypair}[2]{\mathopen{\mydc{$\langle$}}#1\mathpunct{\mydc{,}} #2\mathclose{\mydc{$\rangle$}}}
99 \newcommand{\myfst}{\myfld{fst}}
100 \newcommand{\mysnd}{\myfld{snd}}
101 \newcommand{\myconst}{\myse{c}}
102 \newcommand{\myemptyctx}{\varepsilon}
103 \newcommand{\myhole}{\AgdaHole}
104 \newcommand{\myfix}[3]{\mysyn{fix} \myappsp #1 {:} #2 \mapsto #3}
105 \newcommand{\mysum}{\mathbin{\textcolor{AgdaDatatype}{+}}}
106 \newcommand{\myleft}[1]{\mydc{left}_{#1}}
107 \newcommand{\myright}[1]{\mydc{right}_{#1}}
108 \newcommand{\myempty}{\mytyc{Empty}}
109 \newcommand{\mycase}[2]{\mathopen{\myfun{[}}#1\mathpunct{\myfun{,}} #2 \mathclose{\myfun{]}}}
110 \newcommand{\myabsurd}[1]{\myfun{absurd}_{#1}}
111 \newcommand{\myarg}{\_}
112 \newcommand{\myderivsp}{}
113 \newcommand{\myderivspp}{\vspace{0.3cm}}
114 \newcommand{\mytyp}{\mytyc{Type}}
115 \newcommand{\myneg}{\myfun{$\neg$}}
116 \newcommand{\myar}{\,}
117 \newcommand{\mybool}{\mytyc{Bool}}
118 \newcommand{\mytrue}{\mydc{true}}
119 \newcommand{\myfalse}{\mydc{false}}
120 \newcommand{\myitee}[5]{\myfun{if}\,#1 / {#2.#3}\,\myfun{then}\,#4\,\myfun{else}\,#5}
121 \newcommand{\mynat}{\mytyc{$\mathbb{N}$}}
122 \newcommand{\myrat}{\mytyc{$\mathbb{R}$}}
123 \newcommand{\myite}[3]{\myfun{if}\,#1\,\myfun{then}\,#2\,\myfun{else}\,#3}
124 \newcommand{\myfora}[3]{(#1 {:} #2) \myarr #3}
125 \newcommand{\myexi}[3]{(#1 {:} #2) \myprod #3}
126 \newcommand{\mypairr}[4]{\mathopen{\mydc{$\langle$}}#1\mathpunct{\mydc{,}} #4\mathclose{\mydc{$\rangle$}}_{#2{.}#3}}
127 \newcommand{\mynil}{\mydc{[]}}
128 \newcommand{\mycons}{\mathbin{\mydc{∷}}}
129 \newcommand{\myfoldr}{\myfun{foldr}}
130 \newcommand{\myw}[3]{\myapp{\myapp{\mytyc{W}}{(#1 {:} #2)}}{#3}}
131 \newcommand{\mynodee}{\mathbin{\mydc{$\lhd$}}}
132 \newcommand{\mynode}[2]{\mynodee_{#1.#2}}
133 \newcommand{\myrec}[4]{\myfun{rec}\,#1 / {#2.#3}\,\myfun{with}\,#4}
134 \newcommand{\mylub}{\sqcup}
135 \newcommand{\mydefeq}{\cong}
136 \newcommand{\myrefl}{\mydc{refl}}
137 \newcommand{\mypeq}{\mytyc{=}}
138 \newcommand{\myjeqq}{\myfun{$=$-elim}}
139 \newcommand{\myjeq}[3]{\myapp{\myapp{\myapp{\myjeqq}{#1}}{#2}}{#3}}
140 \newcommand{\mysubst}{\myfun{subst}}
141 \newcommand{\myprsyn}{\myse{prop}}
142 \newcommand{\myprdec}[1]{\mathopen{\mytyc{$\llbracket$}} #1 \mathclose{\mytyc{$\rrbracket$}}}
143 \newcommand{\myand}{\mathrel{\mytyc{$\wedge$}}}
144 \newcommand{\mybigand}{\mathrel{\mytyc{$\bigwedge$}}}
145 \newcommand{\myprfora}[3]{\forall #1 {:} #2.\, #3}
146 \newcommand{\myimpl}{\mathrel{\mytyc{$\Rightarrow$}}}
147 \newcommand{\mybot}{\mytyc{$\bot$}}
148 \newcommand{\mytop}{\mytyc{$\top$}}
149 \newcommand{\mycoe}{\myfun{coe}}
150 \newcommand{\mycoee}[4]{\myapp{\myapp{\myapp{\myapp{\mycoe}{#1}}{#2}}{#3}}{#4}}
151 \newcommand{\mycoh}{\myfun{coh}}
152 \newcommand{\mycohh}[4]{\myapp{\myapp{\myapp{\myapp{\mycoh}{#1}}{#2}}{#3}}{#4}}
153 \newcommand{\myjm}[4]{(#1 {:} #2) \mathrel{\mytyc{=}} (#3 {:} #4)}
154 \newcommand{\myeq}{\mathrel{\mytyc{=}}}
155 \newcommand{\myprop}{\mytyc{Prop}}
156 \newcommand{\mytmup}{\mytmsyn\uparrow}
157 \newcommand{\mydefs}{\Delta}
158 \newcommand{\mynf}{\Downarrow}
159 \newcommand{\myinff}[3]{#1 \vdash #2 \Uparrow #3}
160 \newcommand{\myinf}[2]{\myinff{\myctx}{#1}{#2}}
161 \newcommand{\mychkk}[3]{#1 \vdash #2 \Downarrow #3}
162 \newcommand{\mychk}[2]{\mychkk{\myctx}{#1}{#2}}
163 \newcommand{\myann}[2]{#1 : #2}
164 \newcommand{\mydeclsyn}{\myse{decl}}
165 \newcommand{\myval}[3]{#1 : #2 \mapsto #3}
166 \newcommand{\mypost}[2]{\mysyn{abstract}\ #1 : #2}
167 \newcommand{\myadt}[4]{\mysyn{data}\ #1 #2\ \mysyn{where}\ #3\{ #4 \}}
168 \newcommand{\myreco}[4]{\mysyn{record}\ #1 #2\ \mysyn{where}\ #3\{ #4 \}}
169 \newcommand{\myelabt}{\vdash}
170 \newcommand{\myelabf}{\rhd}
171 \newcommand{\myelab}[2]{\myctx \myelabt #1 \myelabf #2}
172 \newcommand{\mytele}{\Delta}
173 \newcommand{\mytelee}{\delta}
174 \newcommand{\mydcctx}{\Gamma}
175 \newcommand{\mynamesyn}{\myse{name}}
176 \newcommand{\myvec}{\overrightarrow}
177 \newcommand{\mymeta}{\textsc}
178 \newcommand{\myhyps}{\mymeta{hyps}}
179 \newcommand{\mycc}{;}
180 \newcommand{\myemptytele}{\varepsilon}
181 \newcommand{\mymetagoes}{\Longrightarrow}
182 % \newcommand{\mytesctx}{\
183 \newcommand{\mytelesyn}{\myse{telescope}}
184 \newcommand{\myrecs}{\mymeta{recs}}
185 \newcommand{\myle}{\mathrel{\lcfun{$\le$}}}
186 \newcommand{\mylet}{\mysyn{let}}
187 \newcommand{\myhead}{\mymeta{head}}
188 \newcommand{\mytake}{\mymeta{take}}
189 \newcommand{\myix}{\mymeta{ix}}
190 \newcommand{\myapply}{\mymeta{apply}}
191 \newcommand{\mydataty}{\mymeta{datatype}}
192 \newcommand{\myisreco}{\mymeta{record}}
193 \newcommand{\mydcsep}{\ |\ }
194 \newcommand{\mytree}{\mytyc{Tree}}
195 \newcommand{\myproj}[1]{\myfun{$\pi_{#1}$}}
196 \newcommand{\mysigma}{\mytyc{$\Sigma$}}
197 \newcommand{\mynegder}{\vspace{-0.3cm}}
198 \newcommand{\myquot}{\Uparrow}
199 \newcommand{\mynquot}{\, \Downarrow}
200 \newcommand{\mycanquot}{\ensuremath{\textsc{quote}{\Downarrow}}}
201 \newcommand{\myneuquot}{\ensuremath{\textsc{quote}{\Uparrow}}}
202 \newcommand{\mymetaguard}{\ |\ }
203 \newcommand{\mybox}{\Box}
204 \newcommand{\mytermi}[1]{\text{\texttt{#1}}}
205 \newcommand{\mysee}[1]{\langle\myse{#1}\rangle}
206 \newcommand{\mycomp}{\mathbin{\myfun{$\circ$}}}
207 \newcommand{\mylist}[1]{\mathopen{\mytyc{$[$}} #1 \mathclose{\mytyc{$]$}}}
208 \newcommand{\mylistt}[1]{\mathopen{\mydc{$[$}} #1 \mathclose{\mydc{$]$}}}
209 \newcommand{\myplus}{\mathbin{\myfun{$+$}}}
210 \newcommand{\mytimes}{\mathbin{\myfun{$*$}}}
212 \renewcommand{\[}{\begin{equation*}}
213 \renewcommand{\]}{\end{equation*}}
214 \newcommand{\mymacol}[2]{\text{\textcolor{#1}{$#2$}}}
216 \title{\mykant: Implementing Observational Equality}
217 \author{Francesco Mazzoli \texttt{<fm2209@ic.ac.uk>}}
224 \frametitle{Theorem provers are short-sighted}
226 Two functions dear to the Haskell practitioner:
229 \myfun{map} : (\myb{a} \myarr \myb{b}) \myarr \mylist{\myb{a}} \myarr \mylist{\myb{b}} \\
230 \begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
231 \myfun{map} & \myb{f} & \mynil & = & \mynil \\
232 \myfun{map} & \myb{f} & (\myb{x} \mycons \myb{xs}) & = & \myapp{\myb{f}}{\myb{x}} \mycons \myfun{map} \myappsp \myb{f} \myappsp \myb{xs} \\
236 (\myfun{${\circ}$}) : (\myb{b} \myarr \myb{c}) \myarr (\myb{a} \myarr \myb{b}) \myarr (\myb{a} \myarr \myb{c}) \\
237 (\myb{f} \mathbin{\myfun{$\circ$}} \myb{g}) \myappsp \myb{x} = \myapp{\myb{g}}{(\myapp{\myb{f}}{\myb{x}})}
243 \frametitle{Theorem provers are short-sighted}
244 $\myfun{map}$'s composition law states that:
246 \forall \myb{f} {:} (\myb{b} \myarr \myb{c}), \myb{g} {:} (\myb{a} \myarr \myb{b}). \myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g} \myeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g})
248 We can convince Coq or Agda that
250 \forall \myb{f} {:} (\myb{b} \myarr \myb{c}), \myb{g} {:} (\myb{a} \myarr \myb{b}), \myb{l} {:} \mylist{\myb{a}}. (\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g}) \myappsp \myb{l} \myeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) \myappsp \myb{l}
252 But we cannot get rid of the $\myb{l}$. Why?
256 \frametitle{Observational equality and \mykant}
258 \emph{Observational equality} is a solution to this and other equality
261 \mykant\ is a system making observational equality more usable.
263 The theory of \mykant\ is complete, the practice, not quite.
267 \frametitle{Theorem provers, dependent types} First class types: we
268 can return them, have them as arguments, etc.
270 \begin{array}{@{}l@{\ }l@{\ \ \ }l}
271 \mysyn{data}\ \myempty & & \text{No members.} \\
272 \mysyn{data}\ \myunit & = \mytt & \text{One member.} \\
273 \mysyn{data}\ \mynat & = \mydc{zero} \mydcsep \mydc{suc}\myappsp\mynat & \text{Natural numbers.}
276 $\myempty : \mytyp$, $\myunit : \mytyp$, $\mynat : \mytyp$.
278 $\myunit$ is trivially inhabitable: it corresponds to $\top$ in
281 $\myempty$ is \emph{not} inhabitable: it corresponds to $\bot$.
286 \frametitle{Theorem provers, dependent types}
288 We can express relations:
291 (\myfun{${>}$}) : \mynat \myarr \mynat \myarr \mytyp \\
292 \begin{array}{@{}c@{\,}c@{\,}c@{\ }l}
293 \mydc{zero} & \mathrel{\myfun{$>$}} & \myb{m} & = \myempty \\
294 \myb{n} & \mathrel{\myfun{$>$}} & \mydc{zero} & = \myunit \\
295 (\mydc{suc} \myappsp \myb{n}) & \mathrel{\myfun{$>$}} & (\mydc{suc} \myappsp \myb{m}) & = \myb{n} \mathrel{\myfun{$>$}} \myb{m}
300 A term of type $\myb{m} \mathrel{\myfun{$>$}} \myb{n}$ represents a
301 \emph{proof} that $\myb{n}$ is indeed greater than $\myb{n}$.
304 3 \mathrel{\myfun{$>$}} 1 \myred \myunit \\
305 2 \mathrel{\myfun{$>$}} 2 \myred \myempty \\
306 0 \mathrel{\myfun{$>$}} \myb{m} \myred \myempty
310 Thus, proving that $2 \mathrel{\myfun{$>$}} 2$ corresponds to proving
311 falsity, while $3 \mathrel{\myfun{$>$}} 1$ is fine.
315 \frametitle{Example: safe $\myfun{head}$ function}
319 \mysyn{data}\ \mylistt{\myb{A}} = \mynil \mydcsep \myb{A} \mycons \mylistt{\myb{A}} \\
321 \myfun{length} : \mylistt{\myb{A}} \myarr \mynat \\
322 \begin{array}{@{}l@{\myappsp}c@{\ }c@{\ }l}
323 \myfun{length} & \mynil & = & \mydc{zero} \\
324 \myfun{length} & (\myb{x} \mycons \myb{xs}) & = & \mydc{suc} \myappsp (\myfun{length} \myappsp \myb{xs})
327 \myfun{head} : \myfora{\myb{l}}{\mytyc{List}\myappsp\myb{A}}{ \myfun{length}\myappsp\myb{l} \mathrel{\myfun{$>$}} 0 \myarr \myb{A}} \\
328 \begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
329 \myfun{head} & \mynil & \myb{p} & = & \myhole{?} \\
330 \myfun{head} & (\myb{x} \mycons \myb{xs}) & \myb{p} & = & \myb{x}
335 The type of $\myb{p}$ in the $\myhole{?}$ is $\myempty$, since
336 \[\myfun{length} \myappsp \mynil \mathrel{\myfun{$>$}} 0 \myred 0 \mathrel{\myfun{$>$}} 0 \myred \myempty \]
341 \frametitle{Example: safe $\myfun{head}$ function}
345 \mysyn{data}\ \mylistt{\myb{A}} = \mynil \mydcsep \myb{A} \mycons \mylistt{\myb{A}} \\
347 \myfun{length} : \mytyc{List}\myappsp\myb{A} \myarr \mynat \\
348 \begin{array}{@{}l@{\myappsp}c@{\ }c@{\ }l}
349 \myfun{length} & \mynil & = & \mydc{zero} \\
350 \myfun{length} & (\myb{x} \mycons \myb{xs}) & = & \mydc{suc} \myappsp (\myfun{length} \myappsp \myb{xs})
353 \myfun{head} : \myfora{\myb{l}}{\mytyc{List}\myappsp\myb{A}}{ \myfun{length}\myappsp\myb{l} \mathrel{\myfun{$>$}} 0 \myarr \myb{A}} \\
354 \begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
355 \myfun{head} & \mynil & \myb{p} & = & \myabsurd \myappsp \myb{p} \\
356 \myfun{head} & (\myb{x} \mycons \myb{xs}) & \myb{p} & = & \myb{x}
361 Where $\myfun{absurd}$ corresponds to the logical \emph{ex falso
362 quodlibet}---given $\myempty$, we can get anything:
364 \myfun{absurd} : \myempty \myarr \myb{A}
369 \frametitle{How do we type check this thing?}
371 \myfun{head} \myappsp \mylistt{3} : \myfun{length} \myappsp \mylistt{3} \mathrel{\myfun{$>$}} 0 \myarr \mynat
374 Will $\mytt : \myunit$ do as an argument? In other words, when type
375 checking, do we have that
377 \begin{array}{@{}c@{\ }c@{\ }c}
378 \myunit & \mydefeq & \myfun{length} \myappsp \mylistt{3} \mathrel{\myfun{$>$}} 0 \\
379 \myfun{length} \myappsp \mynil \mathrel{\myfun{$>$}} 0 & \mydefeq & \myempty \\
380 (\myabs{\myb{x}\, \myb{y}}{\myb{y}}) \myappsp \myunit \myappsp \myappsp \mynat & \mydefeq & (\myabs{\myb{x}\, \myb{y}}{\myb{x}}) \myappsp \mynat \myappsp \myunit \\
388 \frametitle{Definitional equality}
390 The type checker needs a notion of equality between types.
392 We reduce terms `as far as possible' (to their \emph{normal form}) and
393 then compare them syntactically:
395 \begin{array}{@{}r@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }l}
396 \myunit & \myredd & \myunit & \mydefeq & \myunit & \myreddd & \myfun{length} \myappsp \mylistt{3} \mathrel{\myfun{$>$}} 0 \\
397 \myfun{length} \myappsp \mynil \mathrel{\myfun{$>$}} 0 & \myredd & \myempty & \mydefeq & \myempty & \myreddd & \myempty \\
398 (\myabs{\myb{x}\, \myb{y}}{\myb{y}}) \myappsp \myunit \myappsp \myappsp \mynat & \myredd & \mynat & \mydefeq & \mynat & \myreddd & (\myabs{\myb{x}\, \myb{y}}{\myb{x}}) \myappsp \mynat \myappsp \myunit \\
403 This equality, $\mydefeq$, takes the name of \emph{definitional} equality.
407 \frametitle{Propositional equality} Using definitional equality, we
408 can give the user a type-level notion of term equality.
410 (\myeq) : \myb{A} \myarr \myb{A} \myarr \mytyp
412 We introduce members of $\myeq$ by reflexivity:
414 \myrefl\myappsp\mytmt : \mytmt \myeq \mytmt
416 So that $\myrefl$ will relate definitionally equal terms:
418 \myrefl\myappsp 5 : (3 + 2) \myeq (1 + 4)\ \text{since}\ (3 + 2) \myeq (1 + 4) \myredd 5 \myeq 5
420 Then we can use a substitution law to derive other
421 laws---transitivity, congruence, etc.
425 \frametitle{The problem with prop. equality}
426 Going back to $\myfun{map}$, we can prove that
427 \[ \forall \myb{f} {:} (\myb{b} \myarr \myb{c}), \myb{g} {:} (\myb{a} \myarr \myb{b}), \myb{l} {:} \mylist{\myb{a}}. (\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g}) \myappsp \myb{l} \myeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) \myappsp \myb{l} \]
428 Because we can prove, by induction on $\myb{l}$, that we will always get definitionally equal lists.
430 But without the $\myb{l}$, we cannot compute, so we are stuck with
432 \myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g} \not\mydefeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g})
437 \frametitle{The solution}
439 \emph{Observational} equality, instead of basing its equality on
440 definitional equality, looks at the structure of the type to decide:
443 (\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g} : \mylistt{\myb{A_1}} \myarr \mylistt{\myb{C_1}}) \myeq (\myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) : \mylistt{\myb{A_2}} \myarr \mylistt{\myb{C_2}}) \myred \\
444 \myind{2} (\myb{l_1} : \myb{A_1}) \myarr (\myb{l_2} : \myb{A_2}) \myarr (\myb{l_1} : \myb{A_1}) \myeq (\myb{l_2} : \myb{A_2}) \myarr \\
445 \myind{2} ((\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g}) \myappsp \myb{l} : \mylistt{\myb{C_1}}) \myeq (\myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) \myappsp \myb{l} : \mylistt{\myb{C_2}})
448 This extends to other structures (tuples, inductive types, \dots).
449 Moreover, if we can deem two \emph{types} equal, we can \emph{coerce}
450 values from one to the other.
456 Observational equality was described in a very restricted theory.
458 \mykant\ aims to incorporate it in a more `practical' environment,
461 \item User defined data types (inductive data and records).
462 \item A type hierarchy.
463 \item Partial type inference (bidirectional type checking).
469 \frametitle{Inductive data}
470 Good old Haskell data types:
472 \mysyn{data}\ \mytyc{List}\myappsp \myb{A} = \mynil \mydcsep \myb{A} \mycons \mytyc{List}\myappsp\myb{A}
474 But instead of general recursion and pattern matching, we have
475 structural induction:
477 \begin{array}{@{}l@{\ }l}
478 \mytyc{List}.\myfun{elim} : & (\myb{P} : \mytyc{List}\myappsp\myb{A} \myarr \mytyp) \myarr \\
479 & \myb{P} \myappsp \mynil \myarr \\
480 & ((\myb{x} : \myb{A}) \myarr (\myb{l} : \mytyc{List}\myappsp \myb{A}) \myarr \myb{P} \myappsp \myb{l} \myarr \myb{P} \myappsp (\myb{x} \mycons \myb{l})) \myarr \\
481 & (\myb{l} : \mytyc{List}\myappsp\myb{A}) \myarr \myb{P} \myappsp \myb{l}
486 \begin{array}{@{}l@{\ }l}
487 \mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{pc} \myappsp \mynil & \myred \myse{pn} \\
488 \mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{pc} \myappsp (\mytmm \mycons \mytmn) & \myred \myse{pc} \myappsp \mytmm \myappsp \mytmn \myappsp (\mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{ps} \myappsp \mytmt )
497 \mysyn{record}\ \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B} = \mydc{tuple}\ \{ \myfun{fst} : \myb{A}, \myfun{snd} : \myb{B} \}
499 Where each field defines a projection from instances of the record:
501 \begin{array}{@{}l@{\ }c@{\ }l}
502 \myfun{fst} & : & \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B} \myarr \myb{A} \\
503 \myfun{snd} & : & \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B} \myarr \myb{B}
506 Where the projection's reduction rules are predictably
508 \begin{array}{@{}l@{\ }l}
509 \myfun{fst}\myappsp&(\mydc{tuple}\myappsp\mytmm\myappsp\mytmn) \myred \mytmm \\
510 \myfun{snd}\myappsp&(\mydc{tuple}\myappsp\mytmm\myappsp\mytmn) \myred \mytmn \\
516 \frametitle{Dependend defined types} \emph{Unlike} Haskell, we can
517 have fields of a data constructor to depend on earlier fields:
520 \mysyn{record}\ \mytyc{Tuple}\myappsp(\myb{A} : \mytyp)\myappsp(\myb{B} : \myb{A} \myarr \mytyp) = \\
521 \myind{2}\mydc{tuple}\ \{ \myfun{fst} : \myb{A}, \myfun{snd} : \myb{B}\myappsp\myb{fst} \}
524 $\mytyc{Tuple}$ takes a $\mytyp$, $\myb{A}$, and a predicate from
525 elements of $\myb{A}$ to types, $\myb{B}$.
527 This way, the \emph{type} of the second element depends on the
528 \emph{value} of the first:
530 \begin{array}{@{}l@{\ }l}
531 \myfun{fst} & : \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B} \myarr \myb{A} \\
532 \myfun{snd} & : (\myb{x} : \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B}) \myarr \myb{B} \myappsp (\myfun{fst} \myappsp \myb{x})
538 \frametitle{Type hierarchy}
539 Up to now, we have thrown $\mytyp$ around, as `the type of types'.
541 But what is the type of $\mytyp$ itself? The simple way out is
545 This solution is not only simple, but inconsistent, for the same
546 reason that the notion of a `powerset' in na{\"i}ve set theory is.
548 Instead, following Russell, we shall have
550 \{\mynat, \mybool, \mytyc{List}\myappsp\mynat, \cdots\} : \mytyp_0 : \mytyp_1 : \cdots
552 We talk of types in $\mytyp_0$ as `smaller' than types in $\mytyp_1$.
556 \frametitle{Cumulativity and typical ambiguity}
558 \[ \mytyp_0 : \mytyp_2 \]