on master help sign in
Lots of implementation paper revisions
commit7574d09277023b64857f84efa4c390ffbbd31010 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateThu 14 Feb 2013, 21:53 (14 years ago) parentf31c76a
8 files changed+174−134
papers/impl-paper/conclusions.tex+4−2 papers/impl-paper/delab.tex+3−3 papers/impl-paper/elaboration.tex+102−73 papers/impl-paper/hll.tex+10−13 papers/impl-paper/impldtp.tex+6−6 papers/impl-paper/intro.tex+2−2 papers/impl-paper/library.bib+20−12 papers/impl-paper/typechecking.tex+27−23
papers/impl-paper/conclusions.tex+4−2
@@ -126,8 +126,10 @@ it is possible to expose tactics to the programmer. This opens up
126126the possibility of implementing domain specific decision procedures, or
127127implementing user defined tactics in a style similar to Coq's \texttt{Ltac}
128128language \cite{Delahaye2000}. Although \TT{} is primarily intended as a core
129−language for \Idris{}, its rich type system also allows it to capture a number
130−of high level languages, especially when augmented with primitive operators.
129+language for \Idris{}, its rich type system also means that it could be used
130+as a core language for other high level languages, especially when augmented
131+with primitive operators, and used to express additional properties of those
132+languages.
131133
132134We have not discussed the performance of the elaboration
133135algorithm, or described how \Idris{} compiles to executable code. In practice,
papers/impl-paper/delab.tex+3−3
@@ -77,12 +77,12 @@ which arguments are implicit or constraint arguments:
7777\end{array}
7878\medskip\\
7979\begin{array}{ll}
80−\MO{UnelabTyDecl}\:\vi\:(\all{\vx}{\vT}\SC\ve)
81−\mq & \piimp{\vx}{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
80+\MO{UnelabTyDecl}\:\vi\:(\all{\vy}{\vT}\SC\ve)
81+\mq & \piimp{\vy}{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
8282 & \hg\mbox{(if the $i$th argument to $\vx$ is an implicit argument)} \\
8383 & \piconst{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
8484 & \hg\mbox{(if the $i$th argument to $\vx$ is a constraint argument)} \\
85− & \piexp{\vx}{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
85+ & \piexp{\vy}{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
8686 & \hg\mbox{(otherwise)} \\
8787\end{array}
8888}
papers/impl-paper/elaboration.tex+102−73
@@ -180,7 +180,7 @@ global context $\vC$, $\MO{NewProof}\;\vt$ sets up the proof state as:
180180
181181The local context is initially empty, and the initial hole queue is the $\vx$ standing for
182182the entire expression. The proof term is reset with the $\MO{NewTerm}$ operation.
183−In an existing proof state $(\vC, \Delta, \ve, \vQ)$,
183+In an existing proof state $(\vC, \Delta, \ve, \vP, \vQ)$,
184184$\MO{NewTerm}\;\vt$ discards the proof term and hole queue, and
185185updates the proof state to:
186186
@@ -217,6 +217,9 @@ may fail. We have the following primitive meta-operations:
217217$\Gamma$, returning its type.
218218$\MO{Check}$ will fail
219219if the expression is not well-typed.
220+\item $\MO{Convert}_\Gamma\;\ve_1\;\ve_2$, which checks that the well-typed
221+expressions $\ve_1$ and $\ve_2$ respect the cumulativity relation
222+(i.e. $\Gamma\proves\ve_1\cumul\ve_2$), and fails otherwise.
220223\item $\Eval\;\ve$, which evaluates a well-typed expression $\ve$ relative to a context
221224$\Gamma$, returning its normal form. $\MO{Normalise}$ reduces under binders,
222225but does not reduce definitions which are not total.
@@ -226,19 +229,20 @@ which attempts to unify $\ve_1$ and $\ve_2$ by finding the values with which
226229holes must be instantiated for $\ve_1$ and $\ve_2$ to be convertible relative
227230to $\Gamma$ (i.e. for $\Gamma\proves\ve_1\converts\ve_2$ to hold).
228231\item $\Subst\;\vx\;\ve$, which instantiates a hole $\vx$ directly with a term
229−$\ve$, typically arising from unification.
232+$\ve$, typically arising from unification and removes $\vx$ from the hole
233+queue.
230234\end{itemize}
231235
232236\noindent
233−Additionally, we have $\MO{Focus}$, $\MO{Unfocus}$, $\MO{NewHole}$
234−and $\MO{NextHole}$
237+Additionally, we have $\MO{Focus}$, $\MO{Unfocus}$, $\MO{NewHole}$,
238+$\MO{NextHole}$ and $\MO{RemoveHole}$
235239operations which manipulate and inspect
236240the hole queue. $\MO{Focus}\;\vn$ moves a hole to the head of the hole queue:
237241
238242\DM{
239243\MO{Focus}\;\vn\;=\;\RW{do}\;\AR{
240−(\vC,\Delta,\vP,\vQ;\vn;\vQ')\gets\MO{Get}\\
241−\MO{Put}\;(\vC,\Delta,\vP,\vn;\vQ;\vQ')\\
244+(\vC,\Delta,\ve,\vP,\vQ;\vn;\vQ')\gets\MO{Get}\\
245+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vn;\vQ;\vQ')\\
242246}
243247}
244248
@@ -248,25 +252,31 @@ end of the hole queue:
248252
249253\DM{
250254\MO{Unfocus}\;=\;\RW{do}\;\AR{
251−(\vC,\Delta,\vP,\vn;\vQ)\gets\MO{Get}\\
252−\MO{Put}\;(\vC,\Delta,\vP,\vQ;\vn)\\
255+(\vC,\Delta,\ve,\vP,\vn;\vQ)\gets\MO{Get}\\
256+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vQ;\vn)\\
253257}
254258}
255259
256260\noindent
257261$\MO{NewHole}$ declares that a new hole has been created and is to be solved
258−next, and $\MO{NextHole}$ returns the next hole to be solved:
262+next; $\MO{NextHole}$ returns the next hole to be solved, and $\MO{RemoveHole}$
263+removes a hole from the head of the queue:
259264
260265\DM{
261266\AR{
262267\MO{NewHole}\;=\;\RW{do}\;\AR{
263268(\vC,\Delta,\vP,\vQ)\gets\MO{Get}\\
264−\MO{Put}\;(\vC,\Delta,\vP,\vn;\vQ)\\
269+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vn;\vQ)\\
265270}
266271\\
267272\MO{NextHole}\;=\;\RW{do}\;\AR{
268−(\vC,\Delta,\vP,\vn;\vQ)\gets\MO{Get}\\
269−\MO{Return}\;\vn
273+(\vC,\Delta,\ve,\vP,\vn;\vQ)\gets\MO{Get}\\
274+\RW{return}\;\vn
275+}
276+\\
277+\MO{RemoveHole}\;=\;\RW{do}\;\AR{
278+(\vC,\Delta,\ve,\vP,\vn;\vQ)\gets\MO{Get}\\
279+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vQ)
270280}
271281}
272282}
@@ -278,18 +288,21 @@ form:
278288
279289\DM{
280290\PA{\A\A}{
281−\MO{Tactic}_\Gamma & \;\vec{\VV{args}} & \;\vt & \MoRet{\vt'}
291+\MO{Tac}_\Gamma & \;\vec{\VV{args}} & \;\vt & \MoRet{\RW{do}\;\AR{
292+\ldots\\
293+\RW{return}\:\vt'}
294+}
282295}
283296}
284297
285−A tactic takes a sequence of zero or more arguments $\vec{\VV{args}}$ followed
286−by the sub-term $\vt$ on which it is operating. It runs relative to a context
287−$\Gamma$ which contains all the bindings and pattern bindings in scope at that
288−point in the term. The sub-term $\vt$ will either be a hole binding
289−$\hole{\vx}{\vT}\SC\ve$ or a guess binding $\guess{\vx}{\vT}{\vv}\SC\ve$. The
290−tactic returns a new term $\vt'$ which can take any form, provided it is
291−well-typed, with a type convertible to the type of $\vt$.
292−Tactics may also have the side effect of updating the proof state,
298+A tactic $\MO{Tac}$ takes a sequence of zero or more arguments
299+$\vec{\VV{args}}$ followed by the sub-term $\vt$ on which it is operating. It
300+runs relative to a context $\Gamma$ which contains all the bindings and pattern
301+bindings in scope at that point in the term. The sub-term $\vt$ will either be
302+a hole binding $\hole{\vx}{\vT}\SC\ve$ or a guess binding
303+$\guess{\vx}{\vT}{\vv}\SC\ve$. The tactic returns a new term $\vt'$ which can
304+take any form, provided it is well-typed, with a type convertible to the type
305+of $\vt$. Tactics may also have the side effect of updating the proof state,
293306therefore we will describe tactics in a pseudo-code with $\RW{do}$ notation.
294307
295308Tactics are executed by a higher level meta-operation $\MO{Tactic}$,
@@ -321,23 +334,23 @@ tactic.
321334& \MO{Tactic'} & \Gamma & (\lam{\vx}{\vT}\SC\ve)
322335& \MoRet{
323336\RW{do}\; \AR{\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
324−\lam{\vx}{\vT'}\SC \MO{Tactic'}\;(\Gamma;\lam{\vx}{\vT'})\;\ve}
337+\RW{return}\;(\lam{\vx}{\vT'}\SC \MO{Tactic'}\;(\Gamma;\lam{\vx}{\vT'})\;\ve)}
325338}
326339\\
327340& \MO{Tactic'} & \Gamma & (\all{\vx}{\vT}\SC\ve)
328341& \MoRet{
329342\RW{do}\; \AR{\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
330−\all{\vx}{\vT'}\SC \MO{Tactic'}\;(\Gamma;\all{\vx}{\vT'})\;\ve}
343+\RW{return}\;(\all{\vx}{\vT'}\SC \MO{Tactic'}\;(\Gamma;\all{\vx}{\vT'})\;\ve)}
331344}
332345\\
333346& \MO{Tactic'} & \Gamma & (\LET\;\vx\defq\vt\Hab\vT\SC\ve)
334347& \MoRet{\RW{do}\;\AR{\vt'\Gets\;\MO{Tactic'}\;\Gamma\;\vt\\
335348\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
336−\LET\;\vx\defq\vt'\Hab\vT'\SC
337−\MO{Tactic'}\;(\Gamma;\LET\;\vx\defq\vt'\Hab\vT')\;\ve}} \\
349+\RW{return}\;(\LET\;\vx\defq\vt'\Hab\vT'\SC
350+\MO{Tactic'}\;(\Gamma;\LET\;\vx\defq\vt'\Hab\vT')\;\ve)}} \\
338351& \MO{Tactic'} & \Gamma & (\vf\;\va) &
339−\MoRet{\MO{Return}\;(\MO{Tactic'}\;\Gamma\;\vf)\; (\MO{Tactic'}\;\Gamma\;\va)}\\
340−& \MO{Tactic'} & \Gamma & \vt & \MoRet{\MO{Return}\;\vt}
352+\MoRet{\RW{return}\;(\MO{Tactic'}\;\Gamma\;\vf)\; (\MO{Tactic'}\;\Gamma\;\va)}\\
353+& \MO{Tactic'} & \Gamma & \vt & \MoRet{\RW{return}\;\vt}
341354}
342355}
343356}
@@ -385,7 +398,7 @@ resolve the existing problems with $\MO{ReUnify}$.
385398\AR{
386399(\tx=\te,\tp)\gets\PrimUnify\;\ve_1\;\ve_2\\
387400\vec{\MO{Subst}}\;\tx\;\te\\
388−\MO{SubstProblems}\;(\tx=\te)\\
401+\MO{SubstProblems}\;\tx\;\te\\
389402(\vC,\Delta,\VV{term},\tP,\vQ)\gets\MO{Get}\\
390403\vec{\MO{ReUnify}}\;\tP
391404}
@@ -395,7 +408,7 @@ resolve the existing problems with $\MO{ReUnify}$.
395408\MO{ReUnify}\;(\Gamma,\ve_1,\ve_2)\;=\;\RW{do}\;\AR{
396409(\tx=\te,\tp)\Gets\PrimUnify\;\ve_1\;\ve_2\\
397410\vec{\MO{Subst}}\;\tx\;\te\\
398−\MO{Return}\;\tp
411+\RW{return}\;\tp
399412}
400413}
401414}
@@ -413,14 +426,16 @@ keeping $\vx$ at the head:
413426\DM{
414427\PA{\A\A}{
415428\MO{Claim}_\Gamma & (\vy \Hab\vS) & (\hole{\vx}{\vT}\SC\ve) &
416− \MoRet{\RW{return}\;\hole{\vx}{\vT}\SC\hole{\vy}{\vS}\SC\ve} \\
429+ \MoRet{\RW{do}\;\AR{\MO{NewHole}\;\vy\\
430+ \RW{return}\;\hole{\vx}{\vT}\SC\hole{\vy}{\vS}\SC\ve}} \\
417431}
418432}
419433
420−An obvious difficulty is in ensuring that names are unique throughout a proof term.
421−The implementation ensures that any hole created by the $\MO{Claim}$ tactic
422−has a unique name by checking against existing names in scope and modifying
423−the name if necessary. In this paper, we will assume that all created names are fresh.
434+An obvious difficulty is in ensuring that names are unique throughout a proof
435+term. The implementation ensures that any hole created by the $\MO{NewHole}$
436+operation has a unique name by checking against existing names in scope and
437+modifying the name if necessary. In this paper, we will assume that all created
438+names are fresh.
424439
425440The $\MO{Fill}$ tactic, given a value $\vv$, attempts to solve the current goal
426441with $\vv$, creating a guess binding in its place. $\MO{Fill}$ attempts to
@@ -474,12 +489,14 @@ Therefore the resulting proof term is:
474489
475490The $\MO{Solve}$ tactic operates on a guess binding. If the guess is \remph{pure}, i.e., it
476491is a \TT{} term containing no hole or guess bindings, then the value attached to
477−the guess is substituted into its scope:
492+the guess is substituted into its scope, and the corresponding hole removed
493+from the hole queue:
478494
479495\DM{
480496\PA{\A}{
481497\MO{Solve}_\Gamma & (\guess{\vx}{\vT}{\vv}\SC\ve) &
482− \MoRet{\RW{return}\;\ve[\vv/\vx]\hg\mbox{(if $\MO{Pure}\;\vv$)}}
498+ \MoRet{\RW{do}\;\AR{\MO{RemoveHole}\\
499+ \RW{return}\;\ve[\vv/\vx]\hg\mbox{(if $\MO{Pure}\;\vv$)}}}
483500}
484501}
485502
@@ -523,13 +540,15 @@ binding requires that the goal normalises to a function type:
523540}
524541
525542\noindent
526−Creating a $\forall$ binding requires that the goal is a $\TC{Type}$:
543+Creating a $\forall$ binding requires that the goal type converts
544+with $\TC{Type}$:
527545
528546\DM{
529547\PA{\A\A}{
530548\MO{Pi}_\Gamma & (\vn\Hab\vS) & (\hole{\vx}{\Type}\SC\vx) &
531549 \MoRet{\RW{do}\;\AR{
532− \Type\;\leftarrow\;\Check\;\vS\\
550+ \vV\;\leftarrow\;\Check\;\vS\\
551+ \MO{Convert}_\Gamma\;\vV\;\Type\\
533552 \RW{return}\;\all{\vn}{\vS}\SC\hole{\vx}{\Type}\SC\vx
534553 }
535554 }
@@ -543,7 +562,8 @@ Creating a $\LET$ binding requires a type and a value.
543562\PA{\A\A}{
544563\MO{Let}_\Gamma & (\vn\Hab\vS\defq\vv) & (\hole{\vx}{\vT}\SC\vx) &
545564 \MoRet{\RW{do}\;\AR{
546− \Type\;\leftarrow\;\Check\;\vS\\
565+ \vV\;\leftarrow\;\Check\;\vS\\
566+ \MO{Convert}_\Gamma\;\vV\;\Type\\
547567 \vS'\;\leftarrow\;\Check\;\vv\\
548568 \Unify\;\vS\;\vS'\\
549569 \RW{return}\;\LET\;\vn\Hab\vS\defq\vv\SC\hole{\vx}{\vT}\SC\vx
@@ -798,11 +818,11 @@ Note in particular that each tactic which introduces a guess ($\MO{Fill}$
798818and $\MO{Solve}$ is closed with a $\MO{Solve}$).
799819
800820Setting up elaboration in this way, with a proof state captured in a monad,
801−and a primitive collection of tactics,
802−makes it easy to derive more complex tactics for elaborating higher level language constructs,
803−in much the same way as the \texttt{Ltac} language in Coq. As a result, the
804−description of elaboration of
805−a language construct (or a program such as $\FN{id}$) bears a strong resemblance to
821+and a primitive collection of tactics, makes it easy to derive more complex
822+tactics for elaborating higher level language constructs, in much the same way
823+as the \texttt{Ltac} language in Coq~\cite{Delahaye2000}. As a result, the
824+description of elaboration of a language construct (or a program such as
825+$\FN{id}$) bears a strong resemblance to
806826a Coq proof script.
807827
808828\FFIG{
@@ -865,11 +885,9 @@ The system state is a tuple, $(\vC,\vA,\vI)$, containing:
865885\item Type class information, $\vI$, containing method signatures and dictionaries for type classes
866886\end{itemize}
867887
868−In the implementation, the system state is captured in a monad, \texttt{Idris}.
869−This monad includes additional information such as syntax overloadings,
870−command line options, and optimisations, which do not concern us here. Elaboration
871−of expressions requires access to the system state in particular in order to expand
872−implicit arguments and resolve type classes.
888+In the implementation, the system state is captured in a monad, \texttt{Idris},
889+which includes additional information such as syntax overloadings, command line
890+options, and optimisations, which do not concern us here.
873891
874892For each global name, $\vA$ records whether its arguments are explicit, implicit,
875893or type class constraints. For example, recall the declaration
@@ -996,7 +1014,7 @@ We will use a subset of full \Idris{}, which we call \IdrisM{}, to explain
9961014elaboration of expressions. \IdrisM{} expression syntax is given in Figure
9971015\ref{idrism} and declaration syntax given in Figure \ref{idrismd}.
9981016\IdrisM{} is a subset of \Idris{} without syntactic sugar --- that is, without
999−tuple syntax, \texttt{do}-notation or infix operators --- and with implicit
1017+\texttt{do}-notation or infix operators --- and with implicit
10001018arguments in types bound explicitly
10011019(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\;\va\;\vn$
10021020instead of simply $\Vect\;\va\;\vn$).
@@ -1147,7 +1165,9 @@ $\vV$ and $\vX$.
11471165\ttinterp{\ve}
11481166}
11491167}
1150−\subsubsection{Elaborating applications}
1168+\subsubsection{Elaborating Applications}
1169+
1170+\label{sect:elabapps}
11511171
11521172There are two cases to consider when elaborating applications:
11531173
@@ -1200,17 +1220,21 @@ Finally, any type class instance arguments are resolved with the
12001220built-in $\MO{Instance}$ tactic.
12011221
12021222\DM{
1203−\ttinterp{\vx\;\ta}\;\mq\;
12041223\AR{
1224+\ttinterp{\vx\;\ta}\;\mq\;
12051225\RW{do}\;
12061226\AR{
12071227(\tn,\tv)\;\gets\;\MO{Expand}\;\vx\;\ta\\
12081228\vec{\MO{Claim}}\;(\tn\Hab\tT)\\
12091229\MO{Fill}\;\vx\;\tn\\
1210−\vec{\MO{Focus}}\;\tn;\;\ttinterp{\tv}\hg\mbox{(for non-placeholder $\vv$)}\\
1230+\vec{\MO{ElabArg}}\;\tn\;\tv\hg\mbox{(for non-placeholder $\vv$)}\\
12111231\MO{Solve} \\
12121232\vec{\MO{Instance}}\;\tn\hg\mbox{(for type class constraint argument $\vn$)}
12131233}
1234+\medskip
1235+\\
1236+\MO{ElabArg}\;\vn\;\vv\;\mq\;
1237+\MO{Focus}\;\vn;\;\ttinterp{\vv}
12141238}
12151239}
12161240
@@ -1220,10 +1244,10 @@ context, then recursively searches the global context. $\MO{Instance}$ is covere
12201244in detail in Section \ref{sect:instance}.
12211245
12221246To elaborate a simple function application, of an arbitrary expression to an
1223−arbitrary argument, we need not worry about implicit arguments or class
1224−constraints. Instead, the function and argument are elaborated, and the results
1225−applied. Since elaboration is type directed, however, there must be an
1226−appropriate type for the function.
1247+arbitrary argument (possibly with a dependent type), we need not worry about
1248+implicit arguments or class constraints. Instead, the function and argument are
1249+elaborated, and the results applied. Since elaboration is type directed,
1250+however, there must be an appropriate type for the function.
12271251
12281252\DM{
12291253\ttinterp{\ve\;\va}\;\mq\;\RW{do}\;
@@ -1446,24 +1470,25 @@ ftest' n False x = ...
14461470
14471471\noindent
14481472Elaboration of \texttt{with} builds the type declaration and auxiliary function
1449−automatically. It checks the left hand side, resulting in a set of patterns
1450−$\tp$, then splits these patterns into those necessary to type
1451−$\vW$, and the rest ($\tp_w$ and $\tp_n$ respectively) using
1473+automatically. The elaborator checks the left hand side, resulting in a set of
1474+patterns $\tp$, then infers a type $\vW$ for the expression $\vw$. The patterns
1475+$\tp$ are then split into those necessary to type $\vW$, and the rest ($\tp_w$
1476+and $\tp_n$ respectively) using
14521477$\MO{SplitContext}$. Then, it builds a new declaration, abstracting over
1453−the matched expression $\ve$ in the types of $\tp_n$.
1478+the matched expression $\vw$ in the types of $\tp_n$.
14541479$\MO{Abstract}\;\ve\;\vw\;\vp$ simply replaces any occurrence of $\vw$ in
14551480$\vp$ with the name $\ve$.
14561481
14571482\DM{
14581483\AR{
1459−\MO{ElabClause}\;(\vx\;\ttt\;\iwith\;\ve\;\vec{\VV{pclause}})\;\mq\\
1484+\MO{ElabClause}\;(\vx\;\ttt\;\iwith\;\vw\;\vec{\VV{pclause}})\;\mq\\
14601485\hg\hg\edo{
14611486\MO{NewProof}\;\TC{Infer};\;
14621487\ttinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
14631488\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
14641489\tp\gets\MO{Patterns}\\
14651490\MO{NewTerm}\;\TC{Infer};\;
1466−\ttinterp{\DC{MkInfer}\;\_\;\ve}\\
1491+\ttinterp{\DC{MkInfer}\;\_\;\vw}\\
14671492\DC{MkInfer}\;\vW\;\vw'\gets\MO{Term}\\
14681493(\tp_w,\tp_n)\;\gets\;\MO{SplitContext}\;\vW\;\tp\\
14691494\MO{TTDecl}\;(\vx'\Hab\tp_{w}\to(\ve\Hab\vW)\to\vec{\MO{Abstract}}\;\ve\;\vw'\;\tp_{n}\to\vT)\\
@@ -1508,7 +1533,9 @@ Therefore, a type class declaration elaborates to a record type containing all
15081533of the functions in the class, and an instance is simply an instance of the
15091534record. The methods are translated to top level functions which extract the
15101535relevant function from the dictionary. For example, for the \texttt{Show} type
1511−class, the \texttt{class} declaration is translated to:
1536+class, the \texttt{class} declaration is translated (in the elaborated code,
1537+using the surface \Idris{} syntax for readability)
1538+to:
15121539
15131540\begin{SaveVerbatim}{showdata}
15141541
@@ -1670,8 +1697,9 @@ constructing programs in \TT{}.
16701697\label{sect:instance}
16711698
16721699When elaborating applications, recall that implicit arguments are filled in by
1673−unification, and type class constraints by an $\MO{Instance}$ tactic which searches
1674−the context for an instance of the required type class.
1700+unification as described in Section \ref{sect:elabapps}, and type class
1701+constraints by an $\MO{Instance}$ tactic which searches the context for an
1702+instance of the required type class.
16751703
16761704The $\MO{Instance}$ tactic begins by trying to find a solution in the local context,
16771705using the $\MO{Trivial}$ tactic, which attempts
@@ -1788,9 +1816,9 @@ the vector append function, containing a metavariable \texttt{append\_rec}:
17881816
17891817\begin{SaveVerbatim}{vappmv}
17901818
1791−(++) : Vect A n -> Vect A m -> Vect A (n + m)
1792−(++) Nil ys = ys
1793−(++) (x :: xs) ys = x :: ?append_rec
1819+(++) : Vect a n -> Vect a m -> Vect a (n + m)
1820+Nil ++ ys = ys
1821+(x :: xs) ++ ys = x :: ?append_rec
17941822
17951823\end{SaveVerbatim}
17961824\useverb{vappmv}
@@ -1862,10 +1890,11 @@ lookup_default_case i xs def (Just x) = x
18621890\end{SaveVerbatim}
18631891\useverb{listlookupmv}
18641892
1865−To elaborate a $\icase$ expression involves \texttt{let} binding the scrutinee of
1866−the $\icase$ expression and creating a metavariable $\VV{xcase}$ to implement the
1867−pattern matching. Then the elaborator builds a new pattern matching definition for $\VV{xcase}$
1868−and elaborate it:
1893+To elaborate a $\icase$ expression involves \texttt{let} binding the scrutinee
1894+of the $\icase$ expression, introducing a new name $\VV{scrutinee}$, and
1895+creating a metavariable $\VV{xcase}$ to implement the pattern matching. Then
1896+the elaborator builds a new pattern matching definition for $\VV{xcase}$ and
1897+elaborates it:
18691898
18701899\DM{
18711900\AR{
papers/impl-paper/hll.tex+10−13
@@ -5,7 +5,8 @@
55\Idris{} is
66a pure functional programming language with dependent types. It is
77eagerly evaluated by default, and compiled via the Epic supercombinator
8−library \cite{brady2011epic}.
8+library~\cite{brady2011epic}, with irrelevant values and proof terms
9+automatically erased~\cite{Brady2003,Brady2005}.
910In this section, I will give a brief introduction to programming in \Idris{},
1011covering the most important features. A full tutorial is available elsewhere
1112\cite{idristutorial}.
@@ -38,14 +39,10 @@ main = putStrLn ("The answer is " ++ show x)
3839\useverb{constprims}
3940
4041\noindent
41−Like Haskell, the main function
42−is called \texttt{main}, and input and output is managed with an \texttt{IO}
43−monad. Unlike Haskell, however, a single colon indicates \texttt{:} a type
44−signature, emphasising the importance of types,
45−and \remph{all} top level functions must have a type
46−signature. This is due to type inference being, in general,
47−undecidable for languages with
48−dependent types.
42+Like Haskell, the main function is called \texttt{main}, and input and output
43+is managed with an \texttt{IO} monad. Unlike Haskell, however, \remph{all} top
44+level functions must have a type signature. This is due to type inference
45+being, in general, undecidable for languages with dependent types.
4946
5047A module declaration also opens a \remph{namespace}. The fully qualified names
5148declared in this module are \texttt{Main.x} and \texttt{Main.main}.
@@ -171,7 +168,7 @@ Any names which are visible in the outer scope are also visible in the
171168\texttt{where} clause (unless they are redefined in the \texttt{where} clause,
172169such as \texttt{xs} here). A name which appears only in the type will be in
173170scope in the \texttt{where} clause if it is a \remph{parameter} to one of the
174−types, i.e. it is fixed across the entire structure. In particular, this means
171+types, i.e. it is fixed across the entire data structure. In particular, this means
175172that the \texttt{a} in the definition of \texttt{reverse} above is the
176173\remph{same} \texttt{a} as in the definition of \texttt{revAcc}, as \texttt{a}
177174is a parameter of \texttt{List}.
@@ -206,7 +203,7 @@ of the type constructor \tTC{Vect} --- it takes a type and a \tTC{Nat} as an
206203argument, where \tTC{Type} stands for the type of types. We say that \tTC{Vect}
207204is \emph{parameterised} by a type, and \emph{indexed} over \tTC{Nat}.
208205The distinction between parameters and indices is that a parameter is fixed
209−across an entire structure, whereas an index may vary.
206+across an entire data structure, whereas an index may vary.
210207Each constructor targets a different part of the family of types. \tDC{Nil} can
211208only be used to construct vectors with zero length, and \tDC{::} to construct
212209vectors with non-zero length. The type of \tDC{::} states explicitly that an element
@@ -247,7 +244,7 @@ This declares
247244\tDC{fO} as the zeroth element of a finite set with \texttt{S k} elements;
248245\texttt{fS n} as the
249246\texttt{n+1}th element of a finite set with \texttt{S k} elements.
250−\tTC{Fin} is indexed by a \tTC{Nat}, which
247+\tTC{Fin} is indexed by \tTC{Nat}, which
251248represents the number of elements in the set.
252249Neither constructor targets \texttt{Fin O}, because we cannot construct an
253250element of an empty set.
@@ -412,7 +409,7 @@ class Show a where
412409\useverb{showclass}
413410
414411\noindent
415−This generates a function of the following type (which we call a \emph{method} of the
412+This declares a function of the following type (which we call a \emph{method} of the
416413\texttt{Show} class):
417414
418415\begin{SaveVerbatim}{showty}
papers/impl-paper/impldtp.tex+6−6
@@ -54,7 +54,7 @@
5454
5555
5656\title
57−[Idris, a General Purpose Dependently Typed Programm Language]
57+[Idris, a General Purpose Dependently Typed Programming Language]
5858{Idris, a General Purpose Dependently Typed Programming Language:
5959Design and Implementation}
6060%Implementing General Purpose Dependently Typed Programming Languages}
@@ -74,8 +74,8 @@ Many components of a dependently typed programming language are by now well
7474understood, for example the underlying type theory, type checking, unification and
7575evaluation. How to combine these components into a realistic and usable high
7676level language is, however, folklore, discovered anew by successive
77−language implementations. In this paper, I describe the implementation of a
78−new dependently typed functional programming language, \Idris{}.
77+language implementations. In this paper, I describe the implementation of
78+\Idris{}, a new dependently typed functional programming language.
7979\Idris{} is intended to be a \emph{general purpose} programming language
8080and as such provides high level concepts such as implicit syntax,
8181type classes and \texttt{do} notation.
@@ -133,9 +133,9 @@ implementation of new high level language constructs.
133133
134134This work was funded by the Scottish Informatics and Computer Science Alliance
135135(SICSA) and by EU Framework 7 Project No. 248828 (ADVANCE). My thanks to
136−Philip H\"{o}lzenspies, Kevin Hammond and Vilhelm Sj\"{o}berg for their
137−comments on an earlier draft of this paper, and to the anonymous referees for
138−their many insightful and constructive comments.
136+Philip H\"{o}lzenspies, Kevin Hammond, Vilhelm Sj\"{o}berg and Falko Spiller
137+for their comments on an earlier draft of this paper, and to the anonymous
138+referees for their many insightful and constructive comments.
139139
140140\bibliographystyle{jfp}
141141\bibliography{library.bib}
papers/impl-paper/intro.tex+2−2
@@ -4,7 +4,7 @@ Dependently typed programming languages, such as Agda \cite{norell2007thesis}
44and Coq \cite{Bertot2004}, have emerged in recent years as a promising approach
55to ensuring the correctness of software. Type checking ensures a program has
66the intended meaning; \emph{dependent} types, where types may be predicated
7−on values, allow a programmer to give a program a \emph{precise} type and
7+on values, allow a programmer to give a program a more precise type and
88hence have increased confidence of its correctness.
99The \Idris{} language
1010\cite{Brady2011a} aims to take this idea further, by providing support for
@@ -121,7 +121,7 @@ This illustrates some basic features of \Idris{}:
121121
122122\begin{itemize}
123123\item A single colon is used for type signatures, and a double colon for the
124−cons operator.
124+cons operator, emphasising the importance of types.
125125\item Functions are defined by pattern matching, with a top level type signature.
126126Names which are free in the type signature (\texttt{a} and \texttt{n}) here
127127are implicitly bound.
papers/impl-paper/library.bib+20−12
@@ -1,18 +1,13 @@
11Automatically generated by Mendeley 1.6
22Any changes to this file will be lost if it is regenerated by Mendeley.
33
4−@techreport{Haskell98,
5−abstract = {Haskell is the world's leading lazy functional programming language and is widely used in teaching, research, and applications. The language continues to develop rapidly, but in 1998 the programming community decided to capture a stable snapshot of the language by introducing Haskell 98. This book constitutes the agreed definition of Haskell 98, the language itself as well as its supporting libraries, and should be a standard reference work for anyone involved in research, teaching, or applications. All Haskell compilers support Haskell 98, so professioanls and educators have a stable base for their work.},
6−author = {{Peyton Jones}, Simon},
7−booktitle = {Language},
8−editor = {Jones, Simon Peyton},
9−isbn = {0521826144},
10−number = {1},
11−publisher = {Cambridge University Press},
12−title = {{Haskell 98 Language and Libraries: The Revised Report}},
13−url = {http://www.amazon.ca/exec/obidos/redirect?tag=citeulike09-20&amp;path=ASIN/0521826144},
14−volume = {13},
15−year = {2002}
4+@inproceedings{Delahaye,
5+author = {Delahaye, David},
6+booktitle = {Proceedings of Logic for Programming and Automated Reasoning ({LPAR})},
7+file = {:Users/edwin/Documents/Mendeley Desktop/Delahaye/A Tactic Language for the System Coq/Delahaye - A Tactic Language for the System Coq - 2000(3).pdf:pdf},
8+title = {{A Tactic Language for the System Coq}},
9+url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.66.9062},
10+year = {2000}
1611}
1712@inproceedings{McBride2006,
1813author = {McBride, C and Goguen, H and McKinna, J},
@@ -146,6 +141,19 @@ author = {Walt, Paul Van Der and Swierstra, Wouter},
146141file = {:Users/edwin/Documents/Mendeley Desktop/Walt, Swierstra/Engineering Proof by Reflection in Agda/Walt, Swierstra - Engineering Proof by Reflection in Agda - Unknown.pdf:pdf},
147142title = {{Engineering Proof by Reflection in Agda}}
148143}
144+@techreport{Haskell98,
145+abstract = {Haskell is the world's leading lazy functional programming language and is widely used in teaching, research, and applications. The language continues to develop rapidly, but in 1998 the programming community decided to capture a stable snapshot of the language by introducing Haskell 98. This book constitutes the agreed definition of Haskell 98, the language itself as well as its supporting libraries, and should be a standard reference work for anyone involved in research, teaching, or applications. All Haskell compilers support Haskell 98, so professioanls and educators have a stable base for their work.},
146+author = {{Peyton Jones}, Simon},
147+booktitle = {Language},
148+editor = {Jones, Simon Peyton},
149+isbn = {0521826144},
150+number = {1},
151+publisher = {Cambridge University Press},
152+title = {{Haskell 98 Language and Libraries: The Revised Report}},
153+url = {http://www.amazon.ca/exec/obidos/redirect?tag=citeulike09-20&amp;path=ASIN/0521826144},
154+volume = {13},
155+year = {2002}
156+}
149157@inproceedings{madhavapeddy2007melange,
150158author = {Madhavapeddy, A. and Ho, A. and Deegan, T. and Scott, D. and Sohan, R.},
151159booktitle = {ACM SIGOPS Operating Systems Review},
papers/impl-paper/typechecking.tex+27−23
@@ -20,9 +20,9 @@ its semantics.
2020The syntax of \TT{} expressions is given in Figure \ref{ttsyn}. This defines:
2121
2222\begin{itemize}
23−\item \demph{Terms}, $\vt$, which are variables, bindings, applications or constants.
24−\item \demph{Bindings}, $\vb$, which are lambda abstractions, let bindings, or function spaces.
25−\item \demph{Constants}, $\vc$, which are integer or string literals, or $\Type_i$, the
23+\item \demph{Terms}, $\vt$, which can be variables, bindings, applications or constants.
24+\item \demph{Bindings}, $\vb$, which can be lambda abstractions, let bindings, or function spaces.
25+\item \demph{Constants}, $\vc$, which can be integer or string literals, or $\Type_i$, the
2626type of types, and may be extended with other primitives.
2727\end{itemize}
2828
@@ -33,8 +33,8 @@ inferred by the machine~\cite{pollack1990implicit}.
3333
3434\FFIG{
3535\begin{array}{rll@{\hg}rll}
36−\vt ::= & \vc & (\mbox{constant}) &
37−\hg\vb ::= & \lam{\vx}{\vt} & (\mbox{abstraction}) \\
36+\mbox{Terms,}\;\vt ::= & \vc & (\mbox{constant}) &
37+\;\mbox{Binders,}\;\vb ::= & \lam{\vx}{\vt} & (\mbox{abstraction}) \\
3838
3939 \mid & \vx & (\mbox{variable}) &
4040 \mid & \LET\;\vx\defq\vt\Hab\vt & (\mbox{let binding}) \\
@@ -47,7 +47,7 @@ inferred by the machine~\cite{pollack1990implicit}.
4747% & & &
4848% \mid & \pty{\vx}{\vt} & (\mbox{pattern type}) \\
4949\medskip\\
50− \vc ::= & \Type_i & (\mbox{type universes}) \\
50+\mbox{Constants,}\;\vc ::= & \Type_i & (\mbox{type universes}) \\
5151 \mid & \vi & (\mbox{integer literal}) \\
5252 \mid & \VV{str} & (\mbox{string literal}) \\
5353\end{array}
@@ -93,8 +93,9 @@ by one of the following schemes:
9393
9494\begin{itemize}
9595\item $\beta$-contraction, which substitutes a value applied to a $\lambda$-binding for
96−the bound variable. We define $\beta$-contraction simply by replacing the $\lambda$-binding
97−with a $\LET$ binding.
96+the bound variable.
97+%We define $\beta$-contraction simply by replacing the $\lambda$-binding
98+%with a $\LET$ binding.
9899\item $\delta$-contraction, which replaces a $\LET$ bound variable with its value.
99100\end{itemize}
100101
@@ -122,7 +123,9 @@ reduction rules.
122123\begin{array}{lc}
123124\beta\mathrm{-contraction} &
124125\Axiom{
125−\Gamma\proves(\lam{\vx}{\vS}\SC\vt)\;\vs\leadsto\LET\;\vx\defq\vs\Hab\vS\SC\vt
126+\Gamma\proves(\lam{\vx}{\vS}\SC\vt)\;\vs\leadsto
127+\vt[\vs/\vx]
128+%\LET\;\vx\defq\vs\Hab\vS\SC\vt
126129} \\
127130\delta\mathrm{-contraction} &
128131\Axiom{
@@ -141,10 +144,11 @@ reduction rules.
141144
142145\label{sect:typerules}
143146
144−The type inference rules for \TT{} expressions are given in Figure \ref{typerules}.
145−These rules use the \demph{cumulativity} relation, defined in
146−Figure \ref{cumul}. The type of types, $\Type_i$ is parameterised by a universe level,
147−to prevent Girard's paradox~\cite{coquand1986analysis}. Cumulativity allows programs at
147+The type inference rules for \TT{} expressions are given in Figure
148+\ref{typerules}. These rules use the \demph{cumulativity} relation, defined in
149+Figure \ref{cumul}. The type of types, $\Type_i$ is parameterised by a universe
150+level, to prevent Girard's paradox~\cite{coquand1986analysis}. There is an
151+infinite hierarchy of predicative universes. Cumulativity allows programs at
148152lower universe levels to inhabit higher universe levels. In practice, universe levels
149153can be left implicit (and will be left implicit in the rest of this paper) ---
150154the type checker generates a graph of constraints between universe levels (such
@@ -513,7 +517,7 @@ trees~\cite{Augustsson1985}.
513517{Metatheoretic properties of \TT{}}
514518{metatheory}
515519
516−We assume that \TT{} respects the usual metatheoretic properties, as shown in
520+We conjecture that \TT{} respects the usual metatheoretic properties, as shown in
517521Figure \ref{metatheory}. Specifically: the \demph{Church-Rosser} property
518522(i.e. that distinct reduction sequences lead to the same normal form);
519523\demph{subject reduction} (i.e. that computation preserves type); the
@@ -536,9 +540,10 @@ takes a simple but pragmatic and effective approach to termination checking:
536540any functions which do not satisfy a syntactic constraint on recursive calls
537541are marked as \emph{partial}. Additionally, any function which calls a partial
538542function or uses a data type which is not strictly positive is also marked as
539−partial. The syntactic constraint we use is that a recursive call in a pattern
540−clause must have an argument which is structurally smaller than an input
541−argument in the same position. \TT{} also marks functions which do not cover
543+partial. We use the size change principle~\cite{Lee2001} to determine whether
544+(possibly mutually defined) recursive functions are guaranteed to
545+terminate.
546+\TT{} also marks functions which do not cover
542547all possible inputs as partial. This totality checking is independent of the
543548rest of the type theory, and can be extended.
544549
@@ -601,11 +606,12 @@ vAdd a (S k) c ((::) a k x xs) ((::) a k y ys)
601606\end{SaveVerbatim}
602607\useverb{vAddImpSolve}
603608
604−Finally, to build the \TT{} definition, we need to find the type of each pattern variable
605−and state it explicitly. This leads to the \TT{} definition in Figure \ref{ttvadd},
606−switching to \TT{} notation from the ASCII \Idris{} syntax.
609+Finally, to build the \TT{} definition, we need to find the type of each
610+pattern variable and state it explicitly. This leads to the following
611+\TT{} definition, switching to \TT{} notation from the ASCII \Idris{}
612+syntax:
607613
608−\FFIG{
614+\DM{
609615\AR{
610616\FN{vAdd} \Hab(\va\Hab\Type)\to(\vn\Hab\Nat)\to\TC{Num}\;\va\to
611617 \Vect\;\va\;\vn\to\Vect\;\va\;\vn\to\Vect\;\va\;\vn\\
@@ -626,8 +632,6 @@ switching to \TT{} notation from the ASCII \Idris{} syntax.
626632}
627633}
628634}
629−{Pairwise addition of vectors in \TT{}}
630−{ttvadd}
631635
632636\subsubsection{An Observation: Programming vs Theorem Proving}
633637