6
\usepackage{beamerthemesplit}
11
\title{Agda II -- Take One}
15
\newcommand\PI[2]{(#1:#2)\to{}}
16
\newcommand\hPI[2]{\{#1:#2\}\to{}}
17
\newcommand\Fun[2]{#1\to#2}
18
\newcommand\lam[1]{\lambda #1\to{}}
19
\newcommand\Cons{\mathrel{::}}
21
\newcommand\To{\Rightarrow}
24
\newcommand\Data[3]{\ensuremath{
25
\mathbf{data}~#1 : #2~\mathbf{where} \\
26
\quad\begin{array}{lcl}
30
\newcommand\Module[2]{\ensuremath{
31
\mathbf{module}~#1~\mathbf{where} \\
37
\newenvironment{code}{
38
\begin{block}{}\(\begin{array}{l}
40
\end{array}\)\end{block}
43
\renewcommand\Bar{~~|~~}
49
\section{Introduction}
50
\frame{\tableofcontents}
52
\subsection{Motivation}
54
\frametitle{What's the point?}
59
\item Solid theoretical foundation (lacking in Agda)
61
\item Small well-defined core language with nice metatheory.
62
\item Transparent translation from the full language to the core language.
67
\item Present the (full) language from a user's perspective.
72
\subsection{The Basics}
74
\frametitle{The Logical Framework}
76
{\small \begin{block}{The Basic Language}\(\begin{array}{llcl}
77
\mbox{(Terms)} & s, t & \Coloneqq & x \Bar c \Bar f \Bar s\,t \Bar \lam xt \Bar \lam{(x:A)}t \\
78
\mbox{(Types)} & A, B & \Coloneqq & \PI xAB \Bar A\to B \Bar t \Bar \alpha \\
79
\mbox{(Sorts)} & \alpha, \beta & \Coloneqq & Set_i \Bar Set \Bar Prop \\
84
\item Note: $Set \neq Prop$.
87
{\small\begin{block}{Example: polymorphic identity}\(\begin{array}{l}
88
id : \PI A{Set} A\to A \\
89
id = \lam{(A:{Set})(x:A)}x
90
\end{array}\)\end{block} }
93
\subsection{Features and Not}
96
\frametitle{What's there and what's not}
101
\item Inductive datatypes
102
\item Functions by pattern matching
103
\item Implicit arguments
107
\item Not Yet Features
110
\item Signatures and structures
111
\item Inductive families
116
\section{Not Yet Features}
118
\subsection{Pi in Set}
121
\frametitle{$\Pi$ in Set}
124
\item What does it mean?
125
\begin{block}{We don't have}\[
126
\infer{\Gamma\vdash\PI xAB:{Set}}
127
{ \Gamma\vdash A:{Set}
128
& \Gamma,x:A\vdash B:{Set}
133
{\small \begin{block}{We can't do}\(\begin{array}{l}
134
Rel~A = A\to A\to{Prop} \\
135
apply : List~(Nat\to Nat)\to List~Nat\to List~Nat \\
136
\end{array}\)\end{block} }
141
\frametitle{$\Pi$ in Set}
143
\item Why don't we have it?
145
\item Ask Thierry... (The metatheory gets tricky when you combine
146
$\eta$-equality and $\Pi$ in ${Set}$.)
149
\item What to do about it:
151
\item Get the metatheory straightened out (e.g. $\eta$-equality for datatypes).
152
\item Abandon $\eta$-equality.
153
\item Abandon $\Pi$ in ${Set}$.
158
\subsection{Signatures and Structures}
161
\frametitle{Signatures and Structures}
164
\item What does it mean?
166
\item In Agda you can say (something like)
168
Pair~A~B = \mathbf{sig}\begin{array}[t]{lcl}
173
p = \mathbf{struct}\begin{array}[t]{lcl}
180
\item Why don't we have it?
182
\item We want to start simple.
183
\item Signatures and structures will appear in Agda II -- Take Two
184
(but probably not in the same form as in Agda).
189
\subsection{Inductive Families}
192
\frametitle{Inductive Families}
195
\item What does it mean?
199
\Data{Vec~(A:{Set})}{Nat\to{Set}}{
200
vnil & : & Vec~A~zero \\
201
vcons & : & \PI n{Nat}A\to Vec~A~n\to Vec~A~(suc~n) \\
205
\item Why don't we have it?
207
\item The inductive families in Agda are very limited in terms of
208
what you can do with them.
209
\item We want something better, which will require some thinking.
216
\subsection{Datatypes}
219
\frametitle{Datatypes}
222
\item Standard, garden-variety, strictly positive datatypes:
226
suc & : & Nat\to Nat \\
228
\Data{Exist~(A:{Set})~(P:A\to{Prop})}{Prop}{
229
witness & : & \PI xA P~x\to Exist~A~P
231
\Data{Acc~(A:{Set})~((<):A\to A\to{Prop})~(x:A)}{Prop}{
232
acc & : & (\PI yA y<x\to Acc~A~(<)~y)\to Acc~A~(<)~x
235
\item Note that $\mathbf{data}\ldots$ is a declaration (not a term or type).
239
\subsection{Definitions by Pattern Matching}
242
\frametitle{Definitions by Pattern Matching}
245
\item Functions are defined by pattern matching
247
\item Arbitrarily nested, exhaustive, possibly overlapping patterns.
248
\item No case expressions!
251
\multicolumn5l{(+) : Nat\to Nat\to Nat} \\
253
suc~n &+& m &=& suc~(n + m) \\
257
eqNat : &Nat\to&Nat\to&&Bool \\
258
eqNat&zero&zero &=& true \\
259
eqNat&(suc~n)&(suc~m) &=& eqNat~n~m \\
260
eqNat&\_&\_ &=& false \\
268
\frametitle{Mutual induction-recursion}
271
\item You can have mutually inductive-recursive definitions:
274
\quad\begin{array}{llcl}
275
even : &Nat\to&&Bool \\
276
even&zero &=& true \\
277
even&(suc~n) &=& odd~n \\
279
odd : &Nat\to&&Bool \\
280
odd&zero &=& false \\
281
odd&(suc~n) &=& even~n \\
284
\item I'd show the standard universe construction example of
285
induction-recursion, but you need $\Pi$ in ${Set}$ for that.
291
\frametitle{Local functions}
294
\item Functions (and datatypes) can be local to a definition:
296
reverse : (A:{Set})\to List~A\to List~A \\
297
reverse~A~xs = rev~xs~nil \\
298
\quad\mathbf{where} \\
299
\qquad\begin{array}[t]{lllcl}
300
rev : &List~A\to&List~A\to&&List~A \\
301
rev&nil&ys & = & ys \\
302
rev&(x\Cons xs)&ys & = & rev~xs~(x\Cons ys) \\
309
\frametitle{Termination}
312
\item We allow general recursion.
313
\item Termination checking is done separately (as in Agda).
315
{\small \begin{code}\begin{array}{llcl}
316
qsort : &List~Nat\to&&List~Nat \\
317
qsort &nil &=& nil \\
318
qsort &(x\Cons xs) &=& filter~(\lam yy<x)~xs\mathrel{++} \\
319
&&& x\Cons filter~(\lam yy\geq x)~xs
320
\end{array}\end{code} }
324
\subsection{Implicit Arguments}
327
\frametitle{Meta Variables}
330
\item There are two kinds of meta variables (only one in Agda):
332
\item Interaction points: $?$ and $\{!~\ldots~!\}$
333
\item Go figure\footnote{Conorism}: $\GoFig$
335
\item The type checker should be able to figure out the value of a go
336
figure without user intervention...
337
\item ...whereas the value of an interaction point is supplied by the user.
338
\item We use go figures to implement implicit arguments.
344
\frametitle{Implicit Arguments}
346
\item Curly braces $\{~\}$ are used to indicate implicitness:
347
{\small \begin{block}{Syntax}\(\begin{array}{lcl}
348
s,t & \Coloneqq & \ldots \Bar s~\{t\} \Bar \lam{\{x\}}t \Bar \lam{\{x:A\}}t \Bar \GoFig \\
349
A,B & \Coloneqq & \ldots \Bar \hPI xAB \Bar \{A\}\to B \\
350
\end{array}\)\end{block} }
352
id~:~\hPI A{Set} A\to A \\
354
zero' = id~\{Nat\}~zero \\
356
\item Implicit arguments can be omitted: $id~x$ means $id~\{\GoFig\}~x$.
357
\item Both in left-hand-sides and right-hand-sides:
359
id~:~\hPI A{Set} A\to A \\
370
\Data{List~(A:{Set})}{Set}{
372
(\Cons) & : & A\to List~A\to List~A \\
376
\multicolumn5l{(++) : \hPI A{Set} List~A\to List~A\to List~A} \\
377
nil & ++ & ys &=& ys \\
378
(x::xs) & ++ & ys &=& x::(xs \mathrel{++} ys) \\
382
\item Note that constructors are polymorphic:
384
\item $\vdash nil : List~A$, for any $A$
385
\item $\not\vdash nil : \hPI A{Set}List~A$.
390
\subsection{Module System}
393
\frametitle{Module System}
398
\item Control the scope of names.
399
\item (Not to model algebraic structures.)
401
\item Guiding principle:
403
\item Scope checking should not require type
404
checking or computation.
408
\item Modules are not first class.
414
\frametitle{Submodules}
417
\item Each source file contains a single module, which in turn can
418
contain any number of submodules:
421
\Module{Nat}{\ldots} \\
424
\Module{Fold}{\ldots} \\
433
\frametitle{Accessing the Module Contents}
436
\item To use a module from a file the module has to be {\em imported}\\
438
\mathbf{import}~Prelude
440
\item We can then use the names in the module fully qualified
442
one = Prelude.Nat.suc~Prelude.Nat.zero
444
\item Or we can {\em open} a module
446
\mathbf{open}~Prelude.Nat \\
453
\frametitle{Controlling what is imported}
455
\item We can exercise finer control over what is imported or opened.
457
\mathbf{import}~Prelude~as~P \\
458
\mathbf{open}~P.Nat,~hiding~(+),~renaming~(zero~to~z) \\
459
\mathbf{open}~P.List,~using~(replicate) \\
460
zz : P.List.List~Nat \\
461
zz = replicate~(suc~(suc~z))~z
467
\frametitle{Controlling what is exported}
469
\item Private things are not exported.
472
\mathbf{private}~minorLemma = \ldots \\
473
mainTheorem : P == NP \\
474
mainTheorem = \ldots minorLemma \ldots
477
\item Abstract things export only their type.
481
\quad\begin{array}{l}
482
Stack : Set\to Set \\
487
\item Private things still reduce, abstract things don't.
492
\frametitle{Parameterised Modules}
495
\item Modules can be parameterised.
497
\mathbf{module}~Monad\begin{array}[t]{l}
499
(return:\hPI{A}{Set}A\to M~A) \\
500
((>>=):\hPI{A,B}{Set}M~A\to(A\to M~B)\to M~B)
503
\quad\begin{array}{l}
504
liftM : \hPI{A,B}{Set}(A\to B)\to M~A\to M~B \\
505
liftM~f~m = m \mathrel{>>=} \lam x return~(f~x)
508
\item And instantiated
510
\mathbf{module}~MonadList = Monad~List~singleton~(flip~concatMap) \\
511
lemma : \begin{array}[t]{l}
512
\hPI{A,B}{Set}\PI{f}{A\to B}\PI{xs}{List~A} \\
513
map~f~xs == MonadList.liftM~f~xs \\
516
\item You need to instantiate a parameterised module to use it.
520
\section{Conclusions}
523
\frametitle{That's it folks}
526
\item Agda II is very much work in progress.
527
\item At this point very little is set in stone, so if you think things
528
should be a different way now is the time to speak up.
529
\item Most of what you've seen will be available for use during the 4th
530
Agda Implementors Meeting starting next week in Japan.