talk.tex 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. \documentclass{beamer}
  2. \usetheme{JuanLesPins}
  3. %\usetheme{Darmstadt}
  4. \usepackage{beamerthemesplit}
  5. \usepackage{pxfonts}
  6. \usepackage{proof}
  7. %\usepackage{fleqn}
  8. \title{Agda II -- Take One}
  9. \author{Ulf Norell}
  10. \date{\today}
  11. \newcommand\PI[2]{(#1:#2)\to{}}
  12. \newcommand\hPI[2]{\{#1:#2\}\to{}}
  13. \newcommand\Fun[2]{#1\to#2}
  14. \newcommand\lam[1]{\lambda #1\to{}}
  15. \newcommand\Cons{\mathrel{::}}
  16. \newcommand\To{\Rightarrow}
  17. \newcommand\GoFig{\_}
  18. \newcommand\Data[3]{\ensuremath{
  19. \mathbf{data}~#1 : #2~\mathbf{where} \\
  20. \quad\begin{array}{lcl}
  21. #3
  22. \end{array}
  23. }}
  24. \newcommand\Module[2]{\ensuremath{
  25. \mathbf{module}~#1~\mathbf{where} \\
  26. \quad\begin{array}{l}
  27. #2
  28. \end{array}
  29. }}
  30. \newenvironment{code}{
  31. \begin{block}{}\(\begin{array}{l}
  32. }{
  33. \end{array}\)\end{block}
  34. }
  35. \renewcommand\Bar{~~|~~}
  36. \begin{document}
  37. \frame{\titlepage}
  38. \section{Introduction}
  39. \frame{\tableofcontents}
  40. \subsection{Motivation}
  41. \frame{
  42. \frametitle{What's the point?}
  43. \begin{itemize}
  44. \item of Agda II
  45. \begin{itemize}
  46. \item Solid theoretical foundation (lacking in Agda)
  47. \begin{itemize}
  48. \item Small well-defined core language with nice metatheory.
  49. \item Transparent translation from the full language to the core language.
  50. \end{itemize}
  51. \end{itemize}
  52. \item of this talk
  53. \begin{itemize}
  54. \item Present the (full) language from a user's perspective.
  55. \end{itemize}
  56. \end{itemize}
  57. }
  58. \subsection{The Basics}
  59. \frame{
  60. \frametitle{The Logical Framework}
  61. {\small \begin{block}{The Basic Language}\(\begin{array}{llcl}
  62. \mbox{(Terms)} & s, t & \Coloneqq & x \Bar c \Bar f \Bar s\,t \Bar \lam xt \Bar \lam{(x:A)}t \\
  63. \mbox{(Types)} & A, B & \Coloneqq & \PI xAB \Bar A\to B \Bar t \Bar \alpha \\
  64. \mbox{(Sorts)} & \alpha, \beta & \Coloneqq & Set_i \Bar Set \Bar Prop \\
  65. \end{array}\)
  66. \end{block}}
  67. \begin{itemize}
  68. \item Note: $Set \neq Prop$.
  69. \end{itemize}
  70. {\small\begin{block}{Example: polymorphic identity}\(\begin{array}{l}
  71. id : \PI A{Set} A\to A \\
  72. id = \lam{(A:{Set})(x:A)}x
  73. \end{array}\)\end{block} }
  74. }
  75. \subsection{Features and Not}
  76. \frame{
  77. \frametitle{What's there and what's not}
  78. \begin{itemize}
  79. \item Features
  80. \begin{itemize}
  81. \item Inductive datatypes
  82. \item Functions by pattern matching
  83. \item Implicit arguments
  84. \item Module system
  85. \end{itemize}
  86. ~
  87. \item Not Yet Features
  88. \begin{itemize}
  89. \item $\Pi$ in Set
  90. \item Signatures and structures
  91. \item Inductive families
  92. \end{itemize}
  93. \end{itemize}
  94. }
  95. \section{Not Yet Features}
  96. \subsection{Pi in Set}
  97. \frame{
  98. \frametitle{$\Pi$ in Set}
  99. \begin{itemize}
  100. \item What does it mean?
  101. \begin{block}{We don't have}\[
  102. \infer{\Gamma\vdash\PI xAB:{Set}}
  103. { \Gamma\vdash A:{Set}
  104. & \Gamma,x:A\vdash B:{Set}
  105. }
  106. \]\end{block}
  107. \item Consequences:
  108. {\small \begin{block}{We can't do}\(\begin{array}{l}
  109. Rel~A = A\to A\to{Prop} \\
  110. apply : List~(Nat\to Nat)\to List~Nat\to List~Nat \\
  111. \end{array}\)\end{block} }
  112. \end{itemize}
  113. }
  114. \frame{
  115. \frametitle{$\Pi$ in Set}
  116. \begin{itemize}
  117. \item Why don't we have it?
  118. \begin{itemize}
  119. \item Ask Thierry... (The metatheory gets tricky when you combine
  120. $\eta$-equality and $\Pi$ in ${Set}$.)
  121. \end{itemize}
  122. ~
  123. \item What to do about it:
  124. \begin{itemize}
  125. \item Get the metatheory straightened out (e.g. $\eta$-equality for datatypes).
  126. \item Abandon $\eta$-equality.
  127. \item Abandon $\Pi$ in ${Set}$.
  128. \end{itemize}
  129. \end{itemize}
  130. }
  131. \subsection{Signatures and Structures}
  132. \frame{
  133. \frametitle{Signatures and Structures}
  134. \begin{itemize}
  135. \item What does it mean?
  136. \begin{itemize}
  137. \item In Agda you can say (something like)
  138. {\small \begin{code}
  139. Pair~A~B = \mathbf{sig}\begin{array}[t]{lcl}
  140. fst & : & A \\
  141. snd & : & B \\
  142. \end{array} \\
  143. p : Pair~Nat~Nat \\
  144. p = \mathbf{struct}\begin{array}[t]{lcl}
  145. fst & = & 3 \\
  146. snd & = & 7 \\
  147. \end{array} \\
  148. three = p.fst
  149. \end{code} }
  150. \end{itemize}
  151. \item Why don't we have it?
  152. \begin{itemize}
  153. \item We want to start simple.
  154. \item Signatures and structures will appear in Agda II -- Take Two
  155. (but probably not in the same form as in Agda).
  156. \end{itemize}
  157. \end{itemize}
  158. }
  159. \subsection{Inductive Families}
  160. \frame{
  161. \frametitle{Inductive Families}
  162. \begin{itemize}
  163. \item What does it mean?
  164. \begin{itemize}
  165. \item For instance:
  166. \begin{code}
  167. \Data{Vec~(A:{Set})}{Nat\to{Set}}{
  168. vnil & : & Vec~A~zero \\
  169. vcons & : & \PI n{Nat}A\to Vec~A~n\to Vec~A~(suc~n) \\
  170. }
  171. \end{code}
  172. \end{itemize}
  173. \item Why don't we have it?
  174. \begin{itemize}
  175. \item The inductive families in Agda are very limited in terms of
  176. what you can do with them.
  177. \item We want something better, which will require some thinking.
  178. \end{itemize}
  179. \end{itemize}
  180. }
  181. \section{Features}
  182. \subsection{Datatypes}
  183. \frame{
  184. \frametitle{Datatypes}
  185. \begin{itemize}
  186. \item Standard, garden-variety, strictly positive datatypes:
  187. {\small \begin{code}
  188. \Data{Nat}{Set}{
  189. zero & : & Nat \\
  190. suc & : & Nat\to Nat \\
  191. } \\{}\\
  192. \Data{Exist~(A:{Set})~(P:A\to{Prop})}{Prop}{
  193. witness & : & \PI xA P~x\to Exist~A~P
  194. } \\{}\\
  195. \Data{Acc~(A:{Set})~((<):A\to A\to{Prop})~(x:A)}{Prop}{
  196. acc & : & (\PI yA y<x\to Acc~A~(<)~y)\to Acc~A~(<)~x
  197. }
  198. \end{code} }
  199. \item Note that $\mathbf{data}\ldots$ is a declaration (not a term or type).
  200. \end{itemize}
  201. }
  202. \subsection{Definitions by Pattern Matching}
  203. \frame{
  204. \frametitle{Definitions by Pattern Matching}
  205. \begin{itemize}
  206. \item Functions are defined by pattern matching
  207. \begin{itemize}
  208. \item Arbitrarily nested, exhaustive, possibly overlapping patterns.
  209. \item No case expressions!
  210. {\small \begin{code}
  211. \begin{array}{lclcl}
  212. \multicolumn5l{(+) : Nat\to Nat\to Nat} \\
  213. zero &+& m &=& m \\
  214. suc~n &+& m &=& suc~(n + m) \\
  215. \end{array}\\
  216. {}\\
  217. \begin{array}{lllcl}
  218. eqNat : &Nat\to&Nat\to&&Bool \\
  219. eqNat&zero&zero &=& true \\
  220. eqNat&(suc~n)&(suc~m) &=& eqNat~n~m \\
  221. eqNat&\_&\_ &=& false \\
  222. \end{array}
  223. \end{code} }
  224. \end{itemize}
  225. \end{itemize}
  226. }
  227. \frame{
  228. \frametitle{Mutual induction-recursion}
  229. \begin{itemize}
  230. \item You can have mutually inductive-recursive definitions:
  231. {\small \begin{code}
  232. \mathbf{mutual} \\
  233. \quad\begin{array}{llcl}
  234. even : &Nat\to&&Bool \\
  235. even&zero &=& true \\
  236. even&(suc~n) &=& odd~n \\
  237. \\
  238. odd : &Nat\to&&Bool \\
  239. odd&zero &=& false \\
  240. odd&(suc~n) &=& even~n \\
  241. \end{array}
  242. \end{code} }
  243. \item I'd show the standard universe construction example of
  244. induction-recursion, but you need $\Pi$ in ${Set}$ for that.
  245. \end{itemize}
  246. }
  247. \frame{
  248. \frametitle{Local functions}
  249. \begin{itemize}
  250. \item Functions (and datatypes) can be local to a definition:
  251. {\small \begin{code}
  252. reverse : (A:{Set})\to List~A\to List~A \\
  253. reverse~A~xs = rev~xs~nil \\
  254. \quad\mathbf{where} \\
  255. \qquad\begin{array}[t]{lllcl}
  256. rev : &List~A\to&List~A\to&&List~A \\
  257. rev&nil&ys & = & ys \\
  258. rev&(x\Cons xs)&ys & = & rev~xs~(x\Cons ys) \\
  259. \end{array}
  260. \end{code} }
  261. \end{itemize}
  262. }
  263. \frame{
  264. \frametitle{Termination}
  265. \begin{itemize}
  266. \item We allow general recursion.
  267. \item Termination checking is done separately (as in Agda).
  268. \item Example:
  269. {\small \begin{code}\begin{array}{llcl}
  270. qsort : &List~Nat\to&&List~Nat \\
  271. qsort &nil &=& nil \\
  272. qsort &(x\Cons xs) &=& filter~(\lam yy<x)~xs\mathrel{++} \\
  273. &&& x\Cons filter~(\lam yy\geq x)~xs
  274. \end{array}\end{code} }
  275. \end{itemize}
  276. }
  277. \subsection{Implicit Arguments}
  278. \frame{
  279. \frametitle{Meta Variables}
  280. \begin{itemize}
  281. \item There are two kinds of meta variables (only one in Agda):
  282. \begin{itemize}
  283. \item Interaction points: $?$ and $\{!~\ldots~!\}$
  284. \item Go figure\footnote{Conorism}: $\GoFig$
  285. \end{itemize}
  286. \item The type checker should be able to figure out the value of a go
  287. figure without user intervention...
  288. \item ...whereas the value of an interaction point is supplied by the user.
  289. \item We use go figures to implement implicit arguments.
  290. \end{itemize}
  291. }
  292. \frame{
  293. \frametitle{Implicit Arguments}
  294. \begin{itemize}
  295. \item Curly braces $\{~\}$ are used to indicate implicitness:
  296. {\small \begin{block}{Syntax}\(\begin{array}{lcl}
  297. s,t & \Coloneqq & \ldots \Bar s~\{t\} \Bar \lam{\{x\}}t \Bar \lam{\{x:A\}}t \Bar \GoFig \\
  298. A,B & \Coloneqq & \ldots \Bar \hPI xAB \Bar \{A\}\to B \\
  299. \end{array}\)\end{block} }
  300. {\small \begin{code}
  301. id~:~\hPI A{Set} A\to A \\
  302. id~\{A\}~x = x \\
  303. zero' = id~\{Nat\}~zero \\
  304. \end{code} }
  305. \item Implicit arguments can be omitted: $id~x$ means $id~\{\GoFig\}~x$.
  306. \item Both in left-hand-sides and right-hand-sides:
  307. {\small \begin{code}
  308. id~:~\hPI A{Set} A\to A \\
  309. id~x = x \\
  310. \end{code} }
  311. \end{itemize}
  312. }
  313. \frame{
  314. \frametitle{Example}
  315. \begin{code}
  316. \begin{array}{l}
  317. \Data{List~(A:{Set})}{Set}{
  318. nil & : & List~A \\
  319. (\Cons) & : & A\to List~A\to List~A \\
  320. }
  321. \end{array} \\{}\\
  322. \begin{array}{lclcl}
  323. \multicolumn5l{(++) : \hPI A{Set} List~A\to List~A\to List~A} \\
  324. nil & ++ & ys &=& ys \\
  325. (x::xs) & ++ & ys &=& x::(xs \mathrel{++} ys) \\
  326. \end{array}
  327. \end{code}
  328. \begin{itemize}
  329. \item Note that constructors are polymorphic:
  330. \begin{itemize}
  331. \item $\vdash nil : List~A$, for any $A$
  332. \item $\not\vdash nil : \hPI A{Set}List~A$.
  333. \end{itemize}
  334. \end{itemize}
  335. }
  336. \subsection{Module System}
  337. \frame{
  338. \frametitle{Module System}
  339. \begin{itemize}
  340. \item Purpose:
  341. \begin{itemize}
  342. \item Control the scope of names.
  343. \item (Not to model algebraic structures.)
  344. \end{itemize}
  345. \item Guiding principle:
  346. \begin{itemize}
  347. \item Scope checking should not require type
  348. checking or computation.
  349. \end{itemize}
  350. \item Consequence:
  351. \begin{itemize}
  352. \item Modules are not first class.
  353. \end{itemize}
  354. \end{itemize}
  355. }
  356. \frame{
  357. \frametitle{Submodules}
  358. \begin{itemize}
  359. \item Each source file contains a single module, which in turn can
  360. contain any number of submodules:
  361. {\small \begin{code}
  362. \Module{Prelude}{
  363. \Module{Nat}{\ldots} \\
  364. \Module{List}{
  365. \ldots \\
  366. \Module{Fold}{\ldots} \\
  367. \ldots \\
  368. } \\
  369. }
  370. \end{code} }
  371. \end{itemize}
  372. }
  373. \frame{
  374. \frametitle{Accessing the Module Contents}
  375. \begin{itemize}
  376. \item To use a module from a file the module has to be {\em imported}\\
  377. \begin{code}
  378. \mathbf{import}~Prelude
  379. \end{code}
  380. \item We can then use the names in the module fully qualified
  381. \begin{code}
  382. one = Prelude.Nat.suc~Prelude.Nat.zero
  383. \end{code}
  384. \item Or we can {\em open} a module
  385. \begin{code}
  386. \mathbf{open}~Prelude.Nat \\
  387. one = suc~zero
  388. \end{code}
  389. \end{itemize}
  390. }
  391. \frame{
  392. \frametitle{Controlling what is imported}
  393. \begin{itemize}
  394. \item We can exercise finer control over what is imported or opened.
  395. \begin{code}
  396. \mathbf{import}~Prelude~as~P \\
  397. \mathbf{open}~P.Nat,~hiding~(+),~renaming~(zero~to~z) \\
  398. \mathbf{open}~P.List,~using~(replicate) \\
  399. zz : P.List.List~Nat \\
  400. zz = replicate~(suc~(suc~z))~z
  401. \end{code}
  402. \end{itemize}
  403. }
  404. \frame{
  405. \frametitle{Controlling what is exported}
  406. \begin{itemize}
  407. \item Private things are not exported.
  408. {\small \begin{code}
  409. \Module{BigProof}{
  410. \mathbf{private}~minorLemma = \ldots \\
  411. mainTheorem : P == NP \\
  412. mainTheorem = \ldots minorLemma \ldots
  413. }
  414. \end{code} }
  415. \item Abstract things export only their type.
  416. {\small \begin{code}
  417. \Module{Stack}{
  418. \mathbf{abstract} \\
  419. \quad\begin{array}{l}
  420. Stack : Set\to Set \\
  421. Stack = List \\
  422. \end{array} \\
  423. }
  424. \end{code} }
  425. \item Private things still reduce, abstract things don't.
  426. \end{itemize}
  427. }
  428. \frame{
  429. \frametitle{Parameterised Modules}
  430. \begin{itemize}
  431. \item Modules can be parameterised.
  432. {\small \begin{code}
  433. \mathbf{module}~Monad\begin{array}[t]{l}
  434. (M:Set\to Set) \\
  435. (return:\hPI{A}{Set}A\to M~A) \\
  436. ((>>=):\hPI{A,B}{Set}M~A\to(A\to M~B)\to M~B)
  437. \end{array} \\
  438. ~~~\mathbf{where} \\
  439. \quad\begin{array}{l}
  440. liftM : \hPI{A,B}{Set}(A\to B)\to M~A\to M~B \\
  441. liftM~f~m = m \mathrel{>>=} \lam x return~(f~x)
  442. \end{array}
  443. \end{code}}
  444. \item And instantiated
  445. {\small \begin{code}
  446. \mathbf{module}~MonadList = Monad~List~singleton~(flip~concatMap) \\
  447. lemma : \begin{array}[t]{l}
  448. \hPI{A,B}{Set}\PI{f}{A\to B}\PI{xs}{List~A} \\
  449. map~f~xs == MonadList.liftM~f~xs \\
  450. \end{array}
  451. \end{code} }
  452. \item You need to instantiate a parameterised module to use it.
  453. \end{itemize}
  454. }
  455. \section{Conclusions}
  456. \frame{
  457. \frametitle{That's it folks}
  458. \begin{itemize}
  459. \item Agda II is very much work in progress.
  460. \item At this point very little is set in stone, so if you think things
  461. should be a different way now is the time to speak up.
  462. \item Most of what you've seen will be available for use during the 4th
  463. Agda Implementors Meeting starting next week in Japan.
  464. \end{itemize}
  465. }
  466. % \section{Examples}
  467. %
  468. % \frame{
  469. % }
  470. \end{document}