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 \usepackage{centernot}
16 \usetikzlibrary{shapes,arrows,positioning}
17 \usetikzlibrary{intersections}
18 \pgfdeclarelayer{background}
19 \pgfdeclarelayer{foreground}
20 \pgfsetlayers{background,main,foreground}
23 \setlength{\parindent}{0pt}
24 \setlength{\parskip}{6pt plus 2pt minus 1pt}
25 \setlength{\emergencystretch}{3em} % prevent overfull lines
26 \setcounter{secnumdepth}{0}
28 \usepackage[english]{babel}
29 \usepackage[conor]{agda}
30 \renewcommand{\AgdaKeywordFontStyle}[1]{\ensuremath{\mathrm{\underline{#1}}}}
31 \renewcommand{\AgdaFunction}[1]{\textbf{\textcolor{AgdaFunction}{#1}}}
32 \renewcommand{\AgdaField}{\AgdaFunction}
33 % \definecolor{AgdaBound} {HTML}{000000}
34 \definecolor{AgdaHole} {HTML} {FFFF33}
36 \DeclareUnicodeCharacter{9665}{\ensuremath{\lhd}}
37 \DeclareUnicodeCharacter{964}{\ensuremath{\tau}}
38 \DeclareUnicodeCharacter{963}{\ensuremath{\sigma}}
39 \DeclareUnicodeCharacter{915}{\ensuremath{\Gamma}}
40 \DeclareUnicodeCharacter{8799}{\ensuremath{\stackrel{?}{=}}}
41 \DeclareUnicodeCharacter{9655}{\ensuremath{\rhd}}
43 \newcommand{\mysmall}{}
44 \newcommand{\mysyn}{\AgdaKeyword}
45 \newcommand{\mytyc}[1]{\textup{\AgdaDatatype{#1}}}
46 \newcommand{\mydc}[1]{\textup{\AgdaInductiveConstructor{#1}}}
47 \newcommand{\myfld}[1]{\textup{\AgdaField{#1}}}
48 \newcommand{\myfun}[1]{\textup{\AgdaFunction{#1}}}
49 \newcommand{\myb}[1]{\AgdaBound{$#1$}}
50 \newcommand{\myfield}{\AgdaField}
51 \newcommand{\myind}{\AgdaIndent}
52 \newcommand{\mykant}{{\rmfamily\scshape Bertus}}
53 \newcommand{\mysynel}[1]{#1}
54 \newcommand{\myse}{\mysynel}
55 \newcommand{\mytmsyn}{\langle t \rangle}
56 \newcommand{\mysp}{\ }
57 \newcommand{\myabs}[2]{\mydc{$\lambda$} #1 \mathrel{\mydc{$\mapsto$}} #2}
58 \newcommand{\myappsp}{\hspace{0.07cm}}
59 \newcommand{\myapp}[2]{#1 \myappsp #2}
60 \newcommand{\mysynsep}{\ \ |\ \ }
61 \newcommand{\myITE}[3]{\myfun{If}\, #1\, \myfun{Then}\, #2\, \myfun{Else}\, #3}
62 \newcommand{\mycumul}{\preceq}
64 \newcommand{\mydesc}[3]{
70 \hfill \textup{\phantom{ygp}\textbf{#1}} $#2$
71 \framebox[\textwidth]{
86 \newcommand{\mytmt}{\mysynel{t}}
87 \newcommand{\mytmm}{\mysynel{m}}
88 \newcommand{\mytmn}{\mysynel{n}}
89 \newcommand{\myred}{\leadsto}
90 \newcommand{\myredd}{\stackrel{*}{\leadsto}}
91 \newcommand{\myreddd}{\stackrel{*}{\reflectbox{$\leadsto$}}}
92 \newcommand{\mysub}[3]{#1[#3 / #2]}
93 \newcommand{\mytysyn}{\langle ty \rangle}
94 \newcommand{\mybasetys}{K}
95 \newcommand{\mybasety}[1]{B_{#1}}
96 \newcommand{\mytya}{\myse{A}}
97 \newcommand{\mytyb}{\myse{B}}
98 \newcommand{\mytycc}{\myse{C}}
99 \newcommand{\myarr}{\mathrel{\textcolor{AgdaDatatype}{\to}}}
100 \newcommand{\myprod}{\mathrel{\textcolor{AgdaDatatype}{\times}}}
101 \newcommand{\myctx}{\Gamma}
102 \newcommand{\myvalid}[1]{#1 \vdash \underline{\mathrm{valid}}}
103 \newcommand{\myjudd}[3]{#1 \vdash #2 : #3}
104 \newcommand{\myjud}[2]{\myjudd{\myctx}{#1}{#2}}
105 \newcommand{\myabss}[3]{\mydc{$\lambda$} #1 {:} #2 \mathrel{\mydc{$\mapsto$}} #3}
106 \newcommand{\mytt}{\mydc{$\langle\rangle$}}
107 \newcommand{\myunit}{\mytyc{Unit}}
108 \newcommand{\mypair}[2]{\mathopen{\mydc{$\langle$}}#1\mathpunct{\mydc{,}} #2\mathclose{\mydc{$\rangle$}}}
109 \newcommand{\myfst}{\myfld{fst}}
110 \newcommand{\mysnd}{\myfld{snd}}
111 \newcommand{\myconst}{\myse{c}}
112 \newcommand{\myemptyctx}{\varepsilon}
113 \newcommand{\myhole}{\AgdaHole}
114 \newcommand{\myfix}[3]{\mysyn{fix} \myappsp #1 {:} #2 \mapsto #3}
115 \newcommand{\mysum}{\mathbin{\textcolor{AgdaDatatype}{+}}}
116 \newcommand{\myleft}[1]{\mydc{left}_{#1}}
117 \newcommand{\myright}[1]{\mydc{right}_{#1}}
118 \newcommand{\myempty}{\mytyc{Empty}}
119 \newcommand{\mycase}[2]{\mathopen{\myfun{[}}#1\mathpunct{\myfun{,}} #2 \mathclose{\myfun{]}}}
120 \newcommand{\myabsurd}[1]{\myfun{absurd}_{#1}}
121 \newcommand{\myarg}{\_}
122 \newcommand{\myderivsp}{}
123 \newcommand{\myderivspp}{\vspace{0.3cm}}
124 \newcommand{\mytyp}{\mytyc{Type}}
125 \newcommand{\myneg}{\myfun{$\neg$}}
126 \newcommand{\myar}{\,}
127 \newcommand{\mybool}{\mytyc{Bool}}
128 \newcommand{\mytrue}{\mydc{true}}
129 \newcommand{\myfalse}{\mydc{false}}
130 \newcommand{\myitee}[5]{\myfun{if}\,#1 / {#2.#3}\,\myfun{then}\,#4\,\myfun{else}\,#5}
131 \newcommand{\mynat}{\mytyc{$\mathbb{N}$}}
132 \newcommand{\myrat}{\mytyc{$\mathbb{R}$}}
133 \newcommand{\myite}[3]{\myfun{if}\,#1\,\myfun{then}\,#2\,\myfun{else}\,#3}
134 \newcommand{\myfora}[3]{(#1 {:} #2) \myarr #3}
135 \newcommand{\myexi}[3]{(#1 {:} #2) \myprod #3}
136 \newcommand{\mypairr}[4]{\mathopen{\mydc{$\langle$}}#1\mathpunct{\mydc{,}} #4\mathclose{\mydc{$\rangle$}}_{#2{.}#3}}
137 \newcommand{\mynil}{\mydc{[]}}
138 \newcommand{\mycons}{\mathbin{\mydc{∷}}}
139 \newcommand{\myfoldr}{\myfun{foldr}}
140 \newcommand{\myw}[3]{\myapp{\myapp{\mytyc{W}}{(#1 {:} #2)}}{#3}}
141 \newcommand{\mynodee}{\mathbin{\mydc{$\lhd$}}}
142 \newcommand{\mynode}[2]{\mynodee_{#1.#2}}
143 \newcommand{\myrec}[4]{\myfun{rec}\,#1 / {#2.#3}\,\myfun{with}\,#4}
144 \newcommand{\mylub}{\sqcup}
145 \newcommand{\mydefeq}{\cong}
146 \newcommand{\myrefl}{\mydc{refl}}
147 \newcommand{\mypeq}{\mytyc{=}}
148 \newcommand{\myjeqq}{\myfun{$=$-elim}}
149 \newcommand{\myjeq}[3]{\myapp{\myapp{\myapp{\myjeqq}{#1}}{#2}}{#3}}
150 \newcommand{\mysubst}{\myfun{subst}}
151 \newcommand{\myprsyn}{\myse{prop}}
152 \newcommand{\myprdec}[1]{\mathopen{\mytyc{$\llbracket$}} #1 \mathclose{\mytyc{$\rrbracket$}}}
153 \newcommand{\myand}{\mathrel{\mytyc{$\wedge$}}}
154 \newcommand{\mybigand}{\mathrel{\mytyc{$\bigwedge$}}}
155 \newcommand{\myprfora}[3]{\forall #1 {:} #2.\, #3}
156 \newcommand{\myimpl}{\mathrel{\mytyc{$\Rightarrow$}}}
157 \newcommand{\mybot}{\mytyc{$\bot$}}
158 \newcommand{\mytop}{\mytyc{$\top$}}
159 \newcommand{\mycoe}{\myfun{coe}}
160 \newcommand{\mycoee}[4]{\myapp{\myapp{\myapp{\myapp{\mycoe}{#1}}{#2}}{#3}}{#4}}
161 \newcommand{\mycoh}{\myfun{coh}}
162 \newcommand{\mycohh}[4]{\myapp{\myapp{\myapp{\myapp{\mycoh}{#1}}{#2}}{#3}}{#4}}
163 \newcommand{\myjm}[4]{(#1 {:} #2) \mathrel{\mytyc{=}} (#3 {:} #4)}
164 \newcommand{\myeq}{\mathrel{\mytyc{=}}}
165 \newcommand{\myprop}{\mytyc{Prop}}
166 \newcommand{\mytmup}{\mytmsyn\uparrow}
167 \newcommand{\mydefs}{\Delta}
168 \newcommand{\mynf}{\Downarrow}
169 \newcommand{\myinff}[3]{#1 \vdash #2 \Uparrow #3}
170 \newcommand{\myinf}[2]{\myinff{\myctx}{#1}{#2}}
171 \newcommand{\mychkk}[3]{#1 \vdash #2 \Downarrow #3}
172 \newcommand{\mychk}[2]{\mychkk{\myctx}{#1}{#2}}
173 \newcommand{\myann}[2]{#1 : #2}
174 \newcommand{\mydeclsyn}{\myse{decl}}
175 \newcommand{\myval}[3]{#1 : #2 \mapsto #3}
176 \newcommand{\mypost}[2]{\mysyn{abstract}\ #1 : #2}
177 \newcommand{\myadt}[4]{\mysyn{data}\ #1 #2\ \mysyn{where}\ #3\{ #4 \}}
178 \newcommand{\myreco}[4]{\mysyn{record}\ #1 #2\ \mysyn{where}\ #3\{ #4 \}}
179 \newcommand{\myelabt}{\vdash}
180 \newcommand{\myelabf}{\rhd}
181 \newcommand{\myelab}[2]{\myctx \myelabt #1 \myelabf #2}
182 \newcommand{\mytele}{\Delta}
183 \newcommand{\mytelee}{\delta}
184 \newcommand{\mydcctx}{\Gamma}
185 \newcommand{\mynamesyn}{\myse{name}}
186 \newcommand{\myvec}{\overrightarrow}
187 \newcommand{\mymeta}{\textsc}
188 \newcommand{\myhyps}{\mymeta{hyps}}
189 \newcommand{\mycc}{;}
190 \newcommand{\myemptytele}{\varepsilon}
191 \newcommand{\mymetagoes}{\Longrightarrow}
192 % \newcommand{\mytesctx}{\
193 \newcommand{\mytelesyn}{\myse{telescope}}
194 \newcommand{\myrecs}{\mymeta{recs}}
195 \newcommand{\myle}{\mathrel{\lcfun{$\le$}}}
196 \newcommand{\mylet}{\mysyn{let}}
197 \newcommand{\myhead}{\mymeta{head}}
198 \newcommand{\mytake}{\mymeta{take}}
199 \newcommand{\myix}{\mymeta{ix}}
200 \newcommand{\myapply}{\mymeta{apply}}
201 \newcommand{\mydataty}{\mymeta{datatype}}
202 \newcommand{\myisreco}{\mymeta{record}}
203 \newcommand{\mydcsep}{\ |\ }
204 \newcommand{\mytree}{\mytyc{Tree}}
205 \newcommand{\myproj}[1]{\myfun{$\pi_{#1}$}}
206 \newcommand{\mysigma}{\mytyc{$\Sigma$}}
207 \newcommand{\mynegder}{\vspace{-0.3cm}}
208 \newcommand{\myquot}{\Uparrow}
209 \newcommand{\mynquot}{\, \Downarrow}
210 \newcommand{\mycanquot}{\ensuremath{\textsc{quote}{\Downarrow}}}
211 \newcommand{\myneuquot}{\ensuremath{\textsc{quote}{\Uparrow}}}
212 \newcommand{\mymetaguard}{\ |\ }
213 \newcommand{\mybox}{\Box}
214 \newcommand{\mytermi}[1]{\text{\texttt{#1}}}
215 \newcommand{\mysee}[1]{\langle\myse{#1}\rangle}
216 \newcommand{\mycomp}{\mathbin{\myfun{$\circ$}}}
217 \newcommand{\mylist}[1]{\mytyc{List}\myappsp #1}
218 \newcommand{\mylistt}[1]{\mathopen{\mydc{$[$}} #1 \mathclose{\mydc{$]$}}}
219 \newcommand{\myplus}{\mathbin{\myfun{$+$}}}
220 \newcommand{\mytimes}{\mathbin{\myfun{$*$}}}
221 \newcommand{\mysuc}{\mydc{suc}}
222 \newcommand{\myzero}{\mydc{zero}}
224 \renewcommand{\[}{\begin{equation*}}
225 \renewcommand{\]}{\end{equation*}}
226 \newcommand{\mymacol}[2]{\text{\textcolor{#1}{$#2$}}}
228 \title{\mykant: Implementing Observational Equality}
229 \author{Francesco Mazzoli \texttt{<fm2209@ic.ac.uk>}}
236 \frametitle{\mykant?}
238 \mykant\ is an \emph{interactive theorem prover}/\emph{functional
239 programming language}, implemented in Haskell.
241 It is in the tradition of Agda and Epigram (and to a lesser extent
242 Coq), but with a more powerful notion of \emph{equality}.
244 We have figured out theory of \mykant, and have a near-complete
249 \frametitle{Theorem provers are short-sighted}
251 Two functions dear to the Haskell practitioner:
254 \myfun{map} : (\myb{a} \myarr \myb{b}) \myarr \mylist{\myb{a}} \myarr \mylist{\myb{b}} \\
255 \begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
256 \myfun{map} & \myb{f} & \mynil & = & \mynil \\
257 \myfun{map} & \myb{f} & (\myb{x} \mycons \myb{xs}) & = & \myapp{\myb{f}}{\myb{x}} \mycons \myfun{map} \myappsp \myb{f} \myappsp \myb{xs} \\
261 (\myfun{${\circ}$}) : (\myb{b} \myarr \myb{c}) \myarr (\myb{a} \myarr \myb{b}) \myarr (\myb{a} \myarr \myb{c}) \\
262 (\myb{f} \mathbin{\myfun{$\circ$}} \myb{g}) \myappsp \myb{x} = \myapp{\myb{g}}{(\myapp{\myb{f}}{\myb{x}})}
268 \frametitle{Theorem provers are short-sighted}
269 $\myfun{map}$'s composition law states that:
271 \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})
273 We can convince Coq or Agda that
275 \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}
277 But we cannot get rid of the $\myb{l}$. Why?
281 \frametitle{\mykant\ and observational equality}
283 \emph{Observational} equality solves this and other annoyances.
285 \mykant\ is a system aiming at making observational equality more
290 \frametitle{Theorem provers, dependent types}
293 types $\leftrightarrow$ propositions
295 programs $\leftrightarrow$ proofs
300 \frametitle{Theorem provers, dependent types}
302 \begin{array}{@{}l@{\ \ \ }l}
303 \mysyn{data}\ \myempty & \text{No members.} \\
304 \mysyn{data}\ \myunit \mapsto \mytt & \text{One member.}
308 $\myunit$ is trivially inhabitable: it corresponds to $\top$ in
313 $\myempty$ is \emph{not} inhabitable: it corresponds to $\bot$.
315 \myfun{absurd} : \myempty \myarr \myb{A}
318 First class types: we can return them, have them as arguments, etc:
319 $\myempty : \mytyp$, $\myunit : \mytyp$.
323 \frametitle{Theorem provers, dependent types}
324 \[ \mysyn{data}\ \mylist{\myb{A}} \mapsto \mynil \mydcsep \myb{A} \mycons \mylist{\myb{A}} \]
325 We want to express a `non-emptiness' property for lists:
328 \myfun{non-empty} : \mylist{\myb{A}} \myarr \mytyp \\
329 \begin{array}{@{}l@{\myappsp}c@{\ }l}
330 \myfun{non-empty} & \mynil & \mapsto \myempty \\
331 \myfun{non-empty} & (\myb{x} \mycons \myb{l}) & \mapsto \myunit
336 A term of type $\myfun{non-empty} \myappsp \myb{l}$ represents a
337 \emph{proof} that $\myb{l}$ is indeed not empty.
339 \begin{array}{@{}l@{\ \ \ }l}
340 \text{Can't prove} & \myfun{non-empty}\myappsp \mynil \myred \myempty \\
341 \text{Trivial to prove} & \myfun{non-empty}\myappsp(2 \mycons \mynil) \myred \myunit
347 \frametitle{Example: safe $\myfun{head}$ function}
348 \only<3>{We can eliminate the `empty list' case:}
351 \myfun{head} : \myfora{\myb{l}}{\mytyc{List}\myappsp\myb{A}}{ \myfun{non-empty}\myappsp\myb{l} \myarr \myb{A}} \\
352 \begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
353 \myfun{head} & \mynil & \myb{p} & \mapsto & \only<1,2>{\myhole{?}}\only<3>{\myabsurd\myappsp\myb{p}} \\
354 \myfun{head} & (\myb{x} \mycons \myb{xs}) & \myb{p} & \mapsto & \myb{x}
360 The logic equivalent would be
362 \forall \myb{l} {:} \mylist{\myb{A}}.\ \myfun{non-empty}\myappsp\myb{l} \myarr \myb{A}
364 `For all non-empty lists of type $\myb{A}$, we can get an element of $\myb{A}$.'
367 The type of $\myb{p}$ in the $\myhole{?}$ is $\myempty$, since
368 \[\myfun{non-empty}\myappsp\mynil \myred \myempty \]}
371 \[ \myfun{absurd} : \myempty \myarr \myb{A} \]
376 \frametitle{How do we type check this thing?}
377 \[\text{Is\ } \myfun{non-empty}\myappsp(3 \mycons \mynil) \text{\ the same as\ } \myunit\text{?}\]
378 Or in other words, is
379 \[ \mytt : \myunit \]
382 \myfun{head} \myappsp (3 \mycons \mynil) : \myfun{non-empty}\myappsp(3 \mycons \mynil) \myarr \mynat
385 Yes: to typecheck, we reduce terms fully (to their \emph{normal form})
388 \begin{array}{@{}r@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }l}
389 \myunit & \myredd & \myunit & \mydefeq & \myunit & \myreddd & \myfun{non-empty}\myappsp(3 \mycons \mynil) \\
390 (\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 \\
395 \mydefeq\ \text{takes the name of \textbf{definitional equality}.}
400 \frametitle{Propositional equality} Using definitional equality, we
401 can give the user a type-level notion of term equality.
403 (\myeq) : \myb{A} \myarr \myb{A} \myarr \mytyp\ \ \ \text{internalises equality \textbf{as a type}}
405 We introduce members of $\myeq$ by reflexivity, for example
407 \myrefl\myappsp5 : 5 \myeq 5
412 \myrefl\myappsp 5 : (3 + 2) \myeq (1 + 4)\text{, since}\\
413 (3 + 2) \myeq (1 + 4) \myredd 5 \myeq 5
416 Then we can use a substitution law to derive other
417 laws---transitivity, congruence, etc.
418 \[ \myeq\ \text{takes the name of \textbf{propositional equality}} \]
422 \frametitle{The problem with prop. equality}
423 Going back to $\myfun{map}$, we can prove that
424 \[ \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} \]
427 (\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g})\myappsp \myb{l} \mydefeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) \myappsp \myb{l}
429 By induction on $\myb{l}$.
431 Without the $\myb{l}$ we cannot compute, so we are stuck with
433 \myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g} \not\mydefeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g})
438 \frametitle{Observational equality}
440 Instead of basing its equality on definitional equality, look at the
441 structure of the type to decide.
443 For functions this will mean that proving
445 \myfun{map}\myappsp \myse{f} \mycomp \myfun{map}\myappsp \myse{g} \myeq \myfun{map}\myappsp (\myse{f} \mycomp \myse{g})
447 Will reduce to proving that
449 (\myb{l} : \mylist{\myb{A}}) \myarr
450 (\myfun{map}\myappsp \myse{f} \mycomp \myfun{map}\myappsp \myse{g})\myappsp\myb{l} \myeq \myfun{map}\myappsp (\myse{f} \mycomp \myse{g})\myappsp \myb{l}
452 Which is what we want. The interesting part is how to make the system
458 {\huge \mykant' features}
463 \frametitle{Inductive data}
465 \mysyn{data}\ \mytyc{List}\myappsp (\myb{A} : \mytyp) \mapsto \mynil \mydcsep \myb{A} \mycons \mytyc{List}\myappsp\myb{A}
467 Each with an induction principle:
469 \begin{array}{@{}l@{\ }l}
470 \mytyc{List}.\myfun{elim} : & \AgdaComment{-{}- The property that we want to prove:} \\
471 & (\myb{P} : \mytyc{List}\myappsp\myb{A} \myarr \mytyp) \myarr \\
472 & \AgdaComment{-{}- If it holds for the base case:} \\
473 & \myb{P} \myappsp \mynil \myarr \\
474 & \AgdaComment{-{}- And for the inductive step:} \\
475 & ((\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 \\
476 & \AgdaComment{-{}- Then it holds for every list:} \\
477 & (\myb{l} : \mytyc{List}\myappsp\myb{A}) \myarr \myb{P} \myappsp \myb{l}
480 Induction is also computation, via structural recursion:
482 \begin{array}{@{}l@{\ }l}
483 \mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{pc} \myappsp \mynil & \myred \myse{pn} \\
484 \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 \mytmn )
490 \frametitle{Dependent defined types} \emph{Unlike} Haskell, we can
491 have fields of a data constructor to depend on earlier fields:
494 \mysyn{record}\ \mytyc{Tuple}\myappsp(\myb{A} : \mytyp)\myappsp\myhole{$(\myb{B} : \myb{A} \myarr \mytyp)$} \mapsto \\
495 \myind{2}\mydc{tuple}\ \{ \myfun{fst} : \myb{A}, \myfun{snd} : \myb{B}\myappsp\myb{fst} \}
499 The \emph{type} of the second element depends on the \emph{value} of
502 \begin{array}{@{}l@{\ }l}
503 \myfun{fst} & : \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B} \myarr \myb{A} \\
504 \myfun{snd} & : (\myb{x} : \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B}) \myarr \myb{B} \myappsp (\myfun{fst} \myappsp \myb{x})
507 Where the projection's reduction rules are predictably
509 \begin{array}{@{}l@{\ }l}
510 \myfun{fst}\myappsp&(\mydc{tuple}\myappsp\mytmm\myappsp\mytmn) \myred \mytmm \\
511 \myfun{snd}\myappsp&(\mydc{tuple}\myappsp\mytmm\myappsp\mytmn) \myred \mytmn \\
517 \frametitle{Example: the type of even numbers}
518 For example we can define the type of even numbers:
522 \mysyn{data}\ \mynat \mapsto \mydc{zero} \mydcsep \mydc{suc}\myappsp\mynat \\
524 \myfun{even} : \mynat \myarr \mytyp \\
525 \begin{array}{@{}l@{\myappsp}c@{\ }l}
526 \myfun{even} & \myzero & \mapsto \myunit \\
527 \myfun{even} & (\mysuc \myappsp \myzero) & \mapsto \myempty \\
528 \myfun{even} & (\mysuc \myappsp (\mysuc \myappsp \myb{n})) & \mapsto \myfun{even} \myappsp \myb{n}
531 \mytyc{Even} : \mytyp \\
532 \mytyc{Even} \mapsto \mytyc{Tuple}\ \mynat\ \myfun{even}
538 \frametitle{Type hierarchy}
539 \[\{\mynat, \mybool, \mytyc{List}\myappsp\mynat, \cdots\} : \mytyp\]
540 What is the type of $\mytyp$?
542 \cancel{\mytyp : \mytyp}\ \ \ \text{\textbf{inconsistent}}
544 Similar to Russel's paradox in na{\"i}ve set theory.
546 Instead, we have a hierarchy:
548 \{\mynat, \mybool, \mytyc{List}\myappsp\mynat, \cdots\} : \mytyp_0 : \mytyp_1 : \cdots
550 We talk of types in $\mytyp_0$ as `smaller' than types in $\mytyp_1$.
554 \frametitle{Cumulativity and typical ambiguity}
556 \[ \mytyp_0 : \mytyp_1 \ \ \ \text{but}\ \ \ \mytyp_0 \centernot{:} \mytyp_2\]
557 We have a cumulative hierarchy, so that
558 \[ \mytyp_n : \mytyp_m \ \ \ \text{iff}\ \ \ n < m \]
560 \[ \mynat : \mytyp_0\ \ \ \text{and}\ \ \ \mynat : \mytyp_1\ \ \ \text{and}\ \ \ \mynat : \mytyp_{50} \]
562 But in \mykant, you can forget about levels: the consistency is
563 checked automatically---a mechanised version of what Russell called
564 \emph{typical ambiguity}.
567 \begin{tikzpicture}[remember picture, node distance=1.5cm]
568 \begin{pgfonlayer}{foreground}
571 \node [right of=x] (y) {$y$};
572 \node [right of=y] (z) {$z$};
573 \node [below of=z] (k) {$k$};
574 \node [left of=k] (j) {$j$};
577 (x) edge node [above] {$<$} (y)
578 (y) edge node [above] {$\le$} (z)
579 (z) edge node [right] {$<$} (k)
580 (k) edge node [below] {$\le$} (j)
581 (j) edge node [left ] {$\le$} (y);
582 \end{pgfonlayer}{foreground}
584 \begin{tikzpicture}[remember picture, overlay]
585 \begin{pgfonlayer}{background}
586 \fill [red, opacity=0.3, rounded corners]
587 (-2.7,2.6) rectangle (-0.2,0.05)
588 (-4.1,2.4) rectangle (-3.3,1.6);
589 \end{pgfonlayer}{background}
595 \frametitle{Bidirectional type checking}
597 \mysyn{data}\ \mytyc{List}\myappsp (\myb{A} : \mytyp) \mapsto \mydc{nil} \mydcsep \mydc{cons} \myappsp \myb{A}\myappsp (\mytyc{List}\myappsp\myb{A})
600 With no type inference, we have explicit types for the constructors:
602 \begin{array}{@{}l@{\ }l}
603 \mydc{nil} & : (\myb{A} : \mytyp) \myarr \mytyc{List}\myappsp\myb{A} \\
604 \mydc{cons} &: (\myb{A} : \mytyp) \myarr \myb{A} \myarr \mytyc{List}\myappsp\myb{A} \myarr \mytyc{List}\myappsp\myb{A}\\
609 \mydc{cons}\myappsp \mynat\myappsp 1 \myappsp (\mydc{cons}\myappsp \mynat \myappsp 2 \myappsp (\mydc{cons}\myappsp \mynat \myappsp 3 \myappsp (\mydc{nil}\myappsp \mynat)))
611 Instead, annotate terms and propagate the type:
613 \mydc{cons}\myappsp 1 \myappsp (\mydc{cons}\myappsp 2 \myappsp (\mydc{cons} \myappsp 3 \myappsp \mydc{nil})) : \mytyc{List}\myappsp\mynat
615 Conversely, when we use eliminators the type can be inferred.
619 \frametitle{OTT + user defined types}
621 For each type, we need to:
623 \item Describe when two types formed by the defined type constructors
625 \[ \mylist{\mytya_1} \myeq \mylist{\mytya_2} \]
626 \item Describe when two values of the defined type are equal;
628 \begin{array}{@{}c@{\ \ \ \ \ \ }c}
629 \mynil \myeq \mynil & \mynil \myeq \mytmm \mycons \mytmn \\
630 \mytmm \mycons \mytmn \myeq \mynil & \mytmm_1 \mycons \mytmn_1 \myeq \mytmm_2 \mycons \mytmn_2
633 \item Describe how to transport values of the defined type.
638 \frametitle{OTT + hierarchy}
640 Since equalities reduce to functions abstracting over various things,
641 we need to make sure that the hierarchy is respected.
643 For example we have that
646 \myjm{(\myb{x_1} {:} \mytya_1) \myarr \mytyb_1}{\mytyp}{(\myb{x_2} {:} \mytya_2) \myarr \mytyb_2}{\mytyp} \myred \\
647 \myind{2} \myjm{\mytya_1}{\mytyp}{\mytya_2}{\mytyp} \myand \\
648 \myind{2} ((\myb{x_1} : \mytya_1) \myarr (\myb{x_2} : \mytya_2) \myarr \myjm{\myb{x_1}}{\mytya_1}{\myb{x_2}}{\mytya_2} \myarr \mytyb_1[\myb{x_1}] \myeq \mytyb_2[\myb{x_2}])
652 Subtle point---I discovered a problem in the theory after
653 submitting... but I have a fix.
657 \frametitle{Bonus! WebSocket prompt}
658 \url{http://bertus.mazzo.li}, go DDOS it!
660 \includegraphics[width=\textwidth]{web-prompt.png}
670 \frametitle{What have we done?}
673 \item A small theorem prover for intuitionistic logic, featuring:
674 \item Inductive data and record types;
675 \item A cumulative, implicit type hierarchy;
676 \item Partial type inference---bidirectional type checking;
678 \item Observational equality---coming soon to the implementation.
683 \frametitle{Further work}
686 \item Pattern matching and explicit recursion
687 \item More expressive data types
688 \item Inference via unification