\usepackage{centernot}
\usepackage{cancel}
+\usepackage{tikz}
+\usetikzlibrary{shapes,arrows,positioning}
+\usetikzlibrary{intersections}
+\pgfdeclarelayer{background}
+\pgfdeclarelayer{foreground}
+\pgfsetlayers{background,main,foreground}
+
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\begin{frame}
\frametitle{\mykant?}
- \mykant\ is an \emph{interactive theorem prover}, implemented in
- Haskell.
+ \mykant\ is an \emph{interactive theorem prover}/\emph{functional
+ programming language}, implemented in Haskell.
- It is similar in scope to Agda or Coq, but with a more powerful notion
- of \emph{equality}.
+ It is in the tradition of Agda and Epigram (and to a lesser extent
+ Coq), but with a more powerful notion of \emph{equality}.
- We figured out its theory, but do not have a complete
- implementation---although most of the work is done.
+ We have figured out theory of \mykant, and have a near-complete
+ implementation.
\end{frame}
\begin{frame}
\end{frame}
\begin{frame}
- \frametitle{Theorem provers, dependent types} First class types: we
- can return them, have them as arguments, etc.
+ \frametitle{Theorem provers, dependent types}
\[
- \begin{array}{@{}l@{\ }l@{\ \ \ }l}
- \mysyn{data}\ \myempty & & \text{No members.} \\
- \mysyn{data}\ \myunit & \mapsto \mytt & \text{One member.}
+ \begin{array}{@{}l@{\ \ \ }l}
+ \mysyn{data}\ \myempty & \text{No members.} \\
+ \mysyn{data}\ \myunit \mapsto \mytt & \text{One member.}
\end{array}
\]
- $\myempty : \mytyp$, $\myunit : \mytyp$, $\mynat : \mytyp$.
$\myunit$ is trivially inhabitable: it corresponds to $\top$ in
logic.
-
+ \[
+ \mytt : \myunit
+ \]
$\myempty$ is \emph{not} inhabitable: it corresponds to $\bot$.
\[
\myfun{absurd} : \myempty \myarr \myb{A}
\]
+
+ First class types: we can return them, have them as arguments, etc:
+ $\myempty : \mytyp$, $\myunit : \mytyp$.
\end{frame}
\begin{frame}
\frametitle{Theorem provers, dependent types}
\[ \mysyn{data}\ \mylist{\myb{A}} \mapsto \mynil \mydcsep \myb{A} \mycons \mylist{\myb{A}} \]
We want to express a `non-emptiness' property for lists:
- \[
- \begin{array}{@{}l@{\myappsp}c@{\ }l}
- \myfun{non-empty} : \mylist{\myb{A}} \myarr \mytyp \\
- \myfun{non-empty} & \mynil & = \myempty \\
- \myfun{non-empty} & (\myb{x} \mycons \myb{l}) & = \myunit
- \end{array}
- \]
-
\[
\begin{array}{@{}l}
- (\myfun{${>}$}) : \mynat \myarr \mynat \myarr \mytyp \\
- \begin{array}{@{}c@{\,}c@{\,}c@{\ }l}
- \mydc{zero} & \mathrel{\myfun{$>$}} & \myb{m} & = \myempty \\
- \myb{n} & \mathrel{\myfun{$>$}} & \mydc{zero} & = \myunit \\
- (\mydc{suc} \myappsp \myb{n}) & \mathrel{\myfun{$>$}} & (\mydc{suc} \myappsp \myb{m}) & = \myb{n} \mathrel{\myfun{$>$}} \myb{m}
+ \myfun{non-empty} : \mylist{\myb{A}} \myarr \mytyp \\
+ \begin{array}{@{}l@{\myappsp}c@{\ }l}
+ \myfun{non-empty} & \mynil & \mapsto \myempty \\
+ \myfun{non-empty} & (\myb{x} \mycons \myb{l}) & \mapsto \myunit
\end{array}
\end{array}
\]
- A term of type $\myb{m} \mathrel{\myfun{$>$}} \myb{n}$ represents a
- \emph{proof} that $\myb{m}$ is indeed greater than $\myb{n}$.
+ A term of type $\myfun{non-empty} \myappsp \myb{l}$ represents a
+ \emph{proof} that $\myb{l}$ is indeed not empty.
\[
- \begin{array}{@{}l}
- 3 \mathrel{\myfun{$>$}} 1 \myred \myunit \\
- 2 \mathrel{\myfun{$>$}} 2 \myred \myempty \\
- 0 \mathrel{\myfun{$>$}} \myb{m} \myred \myempty
+ \begin{array}{@{}l@{\ \ \ }l}
+ \text{Can't prove} & \myfun{non-empty}\myappsp \mynil \myred \myempty \\
+ \text{Trivial to prove} & \myfun{non-empty}\myappsp(2 \mycons \mynil) \myred \myunit
\end{array}
\]
\end{frame}
\begin{frame}
\frametitle{Example: safe $\myfun{head}$ function}
-
+ \only<3>{We can eliminate the `empty list' case:}
\[
\begin{array}{@{}l}
- \mysyn{data}\ \mylist{\myb{A}} = \mynil \mydcsep \myb{A} \mycons \mylist{\myb{A}} \\
- \ \\
- \myfun{length} : \mylistt{\myb{A}} \myarr \mynat \\
- \begin{array}{@{}l@{\myappsp}c@{\ }c@{\ }l}
- \myfun{length} & \mynil & \mapsto & \mydc{zero} \\
- \myfun{length} & (\myb{x} \mycons \myb{xs}) & \mapsto & \mydc{suc} \myappsp (\myfun{length} \myappsp \myb{xs})
- \end{array} \\
- \ \\
- \myfun{head} : \myfora{\myb{l}}{\mytyc{List}\myappsp\myb{A}}{ \myfun{length}\myappsp\myb{l} \mathrel{\myfun{$>$}} 0 \myarr \myb{A}} \\
+ \myfun{head} : \myfora{\myb{l}}{\mytyc{List}\myappsp\myb{A}}{ \myfun{non-empty}\myappsp\myb{l} \myarr \myb{A}} \\
\begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
\myfun{head} & \mynil & \myb{p} & \mapsto & \only<1,2>{\myhole{?}}\only<3>{\myabsurd\myappsp\myb{p}} \\
\myfun{head} & (\myb{x} \mycons \myb{xs}) & \myb{p} & \mapsto & \myb{x}
\only<1>{
The logic equivalent would be
\[
- \forall \myb{l} {:} \mylist{\myb{A}}.\ \myfun{length}\myappsp\myb{l} \mathrel{\myfun{$>$}} 0 \myarr \myb{A}
+ \forall \myb{l} {:} \mylist{\myb{A}}.\ \myfun{non-empty}\myappsp\myb{l} \myarr \myb{A}
\]
`For all non-empty lists of type $\myb{A}$, we can get an element of $\myb{A}$.'
}
\only<2>{
The type of $\myb{p}$ in the $\myhole{?}$ is $\myempty$, since
- \[\myfun{length} \myappsp \mynil \mathrel{\myfun{$>$}} 0 \myred 0 \mathrel{\myfun{$>$}} 0 \myred \myempty \]}
+ \[\myfun{non-empty}\myappsp\mynil \myred \myempty \]}
\only<3>{
Remember:
\[ \myfun{absurd} : \myempty \myarr \myb{A} \]
\begin{frame}
\frametitle{How do we type check this thing?}
+ \[\text{Is\ } \myfun{non-empty}\myappsp(3 \mycons \mynil) \text{\ the same as\ } \myunit\text{?}\]
+ Or in other words, is
+ \[ \mytt : \myunit \]
+ A valid argument to
\[
- \myfun{head} \myappsp \mylistt{3} : \myfun{length} \myappsp \mylistt{3} \mathrel{\myfun{$>$}} 0 \myarr \mynat
+ \myfun{head} \myappsp (3 \mycons \mynil) : \myfun{non-empty}\myappsp(3 \mycons \mynil) \myarr \mynat
\]
- Is it the case that
- \[ \mytt : \myfun{length} \myappsp \mylistt{3} \mathrel{\myfun{$>$}} 0 \]
- Or
- \[ \myfun{head} \myappsp \mylistt{3} : \myunit \myarr \mynat \]
- Yes: to typecheck, we reduce terms fully before comparing:
+ Yes: to typecheck, we reduce terms fully (to their \emph{normal form})
+ before comparing:
\[
\begin{array}{@{}r@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }l}
- \myunit & \myredd & \myunit & \mydefeq & \myunit & \myreddd & \myfun{length} \myappsp \mylistt{3} \mathrel{\myfun{$>$}} 0 \\
- \myfun{length} \myappsp \mynil \mathrel{\myfun{$>$}} 0 & \myredd & \myempty & \mydefeq & \myempty & \myreddd & \myempty \\
+ \myunit & \myredd & \myunit & \mydefeq & \myunit & \myreddd & \myfun{non-empty}\myappsp(3 \mycons \mynil) \\
(\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 \\
& & & \vdots & & &
\end{array}
\]
Which is what we want. The interesting part is how to make the system
compute nicely.
-
- This extends to other structures (tuples, inductive types, \dots).
- Moreover, if we can deem two \emph{types} equal, we can \emph{coerce}
- values from one to the other.
\end{frame}
\begin{frame}
\[
\begin{array}{@{}l@{\ }l}
\mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{pc} \myappsp \mynil & \myred \myse{pn} \\
- \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 )
+ \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 )
\end{array}
\]
\end{frame}
% TODO fix
\[
\begin{array}{@{}l}
+ \mysyn{data}\ \mynat \mapsto \mydc{zero} \mydcsep \mydc{suc}\myappsp\mynat \\
+ \ \\
\myfun{even} : \mynat \myarr \mytyp \\
\begin{array}{@{}l@{\myappsp}c@{\ }l}
\myfun{even} & \myzero & \mapsto \myunit \\
\mytyc{Even} \mapsto \mytyc{Tuple}\ \mynat\ \myfun{even}
\end{array}
\]
- In logic this would be
- \[ \exists x \in \mathbb{N}.\ even(x) \]
\end{frame}
\begin{frame}
\[
\cancel{\mytyp : \mytyp}\ \ \ \text{\textbf{inconsistent}}
\]
- Much like na{\"i}ve set theory is (Girard's paradox).
+ Similar to Russel's paradox in na{\"i}ve set theory.
Instead, we have a hierarchy:
\[
But in \mykant, you can forget about levels: the consistency is
checked automatically---a mechanised version of what Russell called
\emph{typical ambiguity}.
+
+ \begin{center}
+ \begin{tikzpicture}[remember picture, node distance=1.5cm]
+ \begin{pgfonlayer}{foreground}
+ % Place nodes
+ \node (x) {$x$};
+ \node [right of=x] (y) {$y$};
+ \node [right of=y] (z) {$z$};
+ \node [below of=z] (k) {$k$};
+ \node [left of=k] (j) {$j$};
+ %% Lines
+ \path[->]
+ (x) edge node [above] {$<$} (y)
+ (y) edge node [above] {$\le$} (z)
+ (z) edge node [right] {$<$} (k)
+ (k) edge node [below] {$\le$} (j)
+ (j) edge node [left ] {$\le$} (y);
+ \end{pgfonlayer}{foreground}
+ \end{tikzpicture}
+ \begin{tikzpicture}[remember picture, overlay]
+ \begin{pgfonlayer}{background}
+ \fill [red, opacity=0.3, rounded corners]
+ (-2.7,2.6) rectangle (-0.2,0.05)
+ (-4.1,2.4) rectangle (-3.3,1.6);
+ \end{pgfonlayer}{background}
+ \end{tikzpicture}
+ \end{center}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Bidirectional type checking}
+ \[
+ \mysyn{data}\ \mytyc{List}\myappsp (\myb{A} : \mytyp) \mapsto \mydc{nil} \mydcsep \mydc{cons} \myappsp \myb{A}\myappsp (\mytyc{List}\myappsp\myb{A})
+ \]
+
+ With no type inference, we have explicit types for the constructors:
+ \[
+ \begin{array}{@{}l@{\ }l}
+ \mydc{nil} & : (\myb{A} : \mytyp) \myarr \mytyc{List}\myappsp\myb{A} \\
+ \mydc{cons} &: (\myb{A} : \mytyp) \myarr \myb{A} \myarr \mytyc{List}\myappsp\myb{A} \myarr \mytyc{List}\myappsp\myb{A}\\
+ \end{array}
+ \]
+ ...ugh:
+ \[
+ \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)))
+ \]
+ Instead, annotate terms and propagate the type:
+ \[
+ \mydc{cons}\myappsp 1 \myappsp (\mydc{cons}\myappsp 2 \myappsp (\mydc{cons} \myappsp 3 \myappsp \mydc{nil})) : \mytyc{List}\myappsp\mynat
+ \]
+ Conversely, when we use eliminators the type can be inferred.
\end{frame}
\begin{frame}
For example we have that
\[
\begin{array}{@{}l}
- ((\myb{x_1} {:} \mytya_1) \myarr \mytyb_1 : \mytyp) \myeq ((\myb{x_2} {:} \mytya_2) \myarr \mytyb_2 : \mytyp) \myred \\
- \myind{2} (\mytya_1 : \mytyp) \myeq (\mytya_2 : \mytyp) \myand \\
- \myind{2} (\myb{x_1} : \mytya_1) \myarr (\myb{x_2} : \mytya_2) \myarr (\mytyb_1 : \mytyp) \myeq (\mytyb_2 : \mytyp)
+ \myjm{(\myb{x_1} {:} \mytya_1) \myarr \mytyb_1}{\mytyp}{(\myb{x_2} {:} \mytya_2) \myarr \mytyb_2}{\mytyp} \myred \\
+ \myind{2} \myjm{\mytya_1}{\mytyp}{\mytya_2}{\mytyp} \myand \\
+ \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}])
\end{array}
\]
\end{frame}
\begin{frame}
- \frametitle{Bidirectional type checking}
- \[
- \mysyn{data}\ \mytyc{List}\myappsp (\myb{A} : \mytyp) \mapsto \mydc{nil} \mydcsep \mydc{cons} \myappsp \myb{A}\myappsp (\mytyc{List}\myappsp\myb{A})
- \]
+ \frametitle{Bonus! WebSocket prompt}
+ \url{http://bertus.mazzo.li}, go DDOS it!
- With no type inference, we have explicit types for the constructors:
- \[
- \begin{array}{@{}l@{\ }l}
- \mydc{nil} & : (\myb{A} : \mytyp) \myarr \mytyc{List}\myappsp\myb{A} \\
- \mydc{cons} &: (\myb{A} : \mytyp) \myarr \myb{A} \myarr \mytyc{List}\myappsp\myb{A} \myarr \mytyc{List}\myappsp\myb{A}\\
- \end{array}
- \]
- ...ugh:
- \[
- \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)))
- \]
- Instead, annotate terms and propagate the type:
- \[
- \mydc{cons}\myappsp 1 \myappsp (\mydc{cons}\myappsp 2 \myappsp (\mydc{cons} \myappsp 3 \myappsp \mydc{nil})) : \mytyc{List}\myappsp\mynat
- \]
- Conversely, when we use eliminators the type can be inferred.
+ \includegraphics[width=\textwidth]{web-prompt.png}
\end{frame}
\begin{frame}
- \frametitle{Bidirectional type checking}
+\begin{center}
+{\Huge Demo}
+\end{center}
+\end{frame}
- This technique is known as \emph{bidirectional} type checking---some
- terms get \emph{checked}, some terms \emph{infer} types.
+\begin{frame}
+ \frametitle{What have we done?}
- Usually used for pre-defined types or core calculi, \mykant\ extends
- to user-defined types.
+ \begin{itemize}
+ \item A small theorem prover for intuitionistic logic, featuring:
+ \item Inductive data and record types;
+ \item A cumulative, implicit type hierarchy;
+ \item Partial type inference---bidirectional type checking;
+ \item Type holes;
+ \item Observational equality---coming soon to the implementation.
+ \end{itemize}
\end{frame}
\begin{frame}
-\begin{center}
-{\Huge Demo}
-\end{center}
+ \frametitle{Further work}
+
+ \begin{itemize}
+ \item Pattern matching and explicit recursion
+ \item More expressive data types
+ \item Inference via unification
+ \item Codata
+ \end{itemize}
\end{frame}
\begin{frame}