@@ -180,7 +180,7 @@ global context $\vC$, $\MO{NewProof}\;\vt$ sets up the proof state as:
181The local context is initially empty, and the initial hole queue is the $\vx$ standing for
181The local context is initially empty, and the initial hole queue is the $\vx$ standing for
182the entire expression. The proof term is reset with the $\MO{NewTerm}$ operation.
182the 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)$,
184$\MO{NewTerm}\;\vt$ discards the proof term and hole queue, and
184$\MO{NewTerm}\;\vt$ discards the proof term and hole queue, and
185updates the proof state to:
185updates the proof state to:
@@ -217,6 +217,9 @@ may fail. We have the following primitive meta-operations:
217$\Gamma$, returning its type.
217$\Gamma$, returning its type.
218$\MO{Check}$ will fail
218$\MO{Check}$ will fail
219if the expression is not well-typed.
219if 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.
220\item $\Eval\;\ve$, which evaluates a well-typed expression $\ve$ relative to a context
223\item $\Eval\;\ve$, which evaluates a well-typed expression $\ve$ relative to a context
221$\Gamma$, returning its normal form. $\MO{Normalise}$ reduces under binders,
224$\Gamma$, returning its normal form. $\MO{Normalise}$ reduces under binders,
222but does not reduce definitions which are not total.
225but 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
226holes must be instantiated for $\ve_1$ and $\ve_2$ to be convertible relative
229holes must be instantiated for $\ve_1$ and $\ve_2$ to be convertible relative
227to $\Gamma$ (i.e. for $\Gamma\proves\ve_1\converts\ve_2$ to hold).
230to $\Gamma$ (i.e. for $\Gamma\proves\ve_1\converts\ve_2$ to hold).
228\item $\Subst\;\vx\;\ve$, which instantiates a hole $\vx$ directly with a term
231\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
230\end{itemize}
234\end{itemize}
233−Additionally, we have $\MO{Focus}$, $\MO{Unfocus}$, $\MO{NewHole}$
237+Additionally, we have $\MO{Focus}$, $\MO{Unfocus}$, $\MO{NewHole}$,
234−and $\MO{NextHole}$
238+$\MO{NextHole}$ and $\MO{RemoveHole}$
235operations which manipulate and inspect
239operations which manipulate and inspect
236the hole queue. $\MO{Focus}\;\vn$ moves a hole to the head of the hole queue:
240the hole queue. $\MO{Focus}\;\vn$ moves a hole to the head of the hole queue:
239\MO{Focus}\;\vn\;=\;\RW{do}\;\AR{
243\MO{Focus}\;\vn\;=\;\RW{do}\;\AR{
240−(\vC,\Delta,\vP,\vQ;\vn;\vQ')\gets\MO{Get}\\
244+(\vC,\Delta,\ve,\vP,\vQ;\vn;\vQ')\gets\MO{Get}\\
241−\MO{Put}\;(\vC,\Delta,\vP,\vn;\vQ;\vQ')\\
245+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vn;\vQ;\vQ')\\
@@ -248,25 +252,31 @@ end of the hole queue:
250\MO{Unfocus}\;=\;\RW{do}\;\AR{
254\MO{Unfocus}\;=\;\RW{do}\;\AR{
251−(\vC,\Delta,\vP,\vn;\vQ)\gets\MO{Get}\\
255+(\vC,\Delta,\ve,\vP,\vn;\vQ)\gets\MO{Get}\\
252−\MO{Put}\;(\vC,\Delta,\vP,\vQ;\vn)\\
256+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vQ;\vn)\\
257$\MO{NewHole}$ declares that a new hole has been created and is to be solved
261$\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:
262\MO{NewHole}\;=\;\RW{do}\;\AR{
267\MO{NewHole}\;=\;\RW{do}\;\AR{
263(\vC,\Delta,\vP,\vQ)\gets\MO{Get}\\
268(\vC,\Delta,\vP,\vQ)\gets\MO{Get}\\
264−\MO{Put}\;(\vC,\Delta,\vP,\vn;\vQ)\\
269+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vn;\vQ)\\
267\MO{NextHole}\;=\;\RW{do}\;\AR{
272\MO{NextHole}\;=\;\RW{do}\;\AR{
268−(\vC,\Delta,\vP,\vn;\vQ)\gets\MO{Get}\\
273+(\vC,\Delta,\ve,\vP,\vn;\vQ)\gets\MO{Get}\\
269−\MO{Return}\;\vn
274+\RW{return}\;\vn
277+\MO{RemoveHole}\;=\;\RW{do}\;\AR{
278+(\vC,\Delta,\ve,\vP,\vn;\vQ)\gets\MO{Get}\\
279+\MO{Put}\;(\vC,\Delta,\ve,\vP,\vQ)
@@ -278,18 +288,21 @@ form:
280\PA{\A\A}{
290\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{
285−A tactic takes a sequence of zero or more arguments $\vec{\VV{args}}$ followed
298+A tactic $\MO{Tac}$ takes a sequence of zero or more arguments
286−by the sub-term $\vt$ on which it is operating. It runs relative to a context
299+$\vec{\VV{args}}$ followed by the sub-term $\vt$ on which it is operating. It
287−$\Gamma$ which contains all the bindings and pattern bindings in scope at that
300+runs relative to a context $\Gamma$ which contains all the bindings and pattern
288−point in the term. The sub-term $\vt$ will either be a hole binding
301+bindings in scope at that point in the term. The sub-term $\vt$ will either be
289−$\hole{\vx}{\vT}\SC\ve$ or a guess binding $\guess{\vx}{\vT}{\vv}\SC\ve$. The
302+a hole binding $\hole{\vx}{\vT}\SC\ve$ or a guess binding
290−tactic returns a new term $\vt'$ which can take any form, provided it is
303+$\guess{\vx}{\vT}{\vv}\SC\ve$. The tactic returns a new term $\vt'$ which can
291−well-typed, with a type convertible to the type of $\vt$.
304+take any form, provided it is well-typed, with a type convertible to the type
292−Tactics may also have the side effect of updating the proof state,
305+of $\vt$. Tactics may also have the side effect of updating the proof state,
293therefore we will describe tactics in a pseudo-code with $\RW{do}$ notation.
306therefore we will describe tactics in a pseudo-code with $\RW{do}$ notation.
295Tactics are executed by a higher level meta-operation $\MO{Tactic}$,
308Tactics are executed by a higher level meta-operation $\MO{Tactic}$,
@@ -321,23 +334,23 @@ tactic.
321& \MO{Tactic'} & \Gamma & (\lam{\vx}{\vT}\SC\ve)
334& \MO{Tactic'} & \Gamma & (\lam{\vx}{\vT}\SC\ve)
323\RW{do}\; \AR{\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
336\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)}
327& \MO{Tactic'} & \Gamma & (\all{\vx}{\vT}\SC\ve)
340& \MO{Tactic'} & \Gamma & (\all{\vx}{\vT}\SC\ve)
329\RW{do}\; \AR{\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
342\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)}
333& \MO{Tactic'} & \Gamma & (\LET\;\vx\defq\vt\Hab\vT\SC\ve)
346& \MO{Tactic'} & \Gamma & (\LET\;\vx\defq\vt\Hab\vT\SC\ve)
334& \MoRet{\RW{do}\;\AR{\vt'\Gets\;\MO{Tactic'}\;\Gamma\;\vt\\
347& \MoRet{\RW{do}\;\AR{\vt'\Gets\;\MO{Tactic'}\;\Gamma\;\vt\\
335\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
348\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
336−\LET\;\vx\defq\vt'\Hab\vT'\SC
349+\RW{return}\;(\LET\;\vx\defq\vt'\Hab\vT'\SC
337−\MO{Tactic'}\;(\Gamma;\LET\;\vx\defq\vt'\Hab\vT')\;\ve}} \\
350+\MO{Tactic'}\;(\Gamma;\LET\;\vx\defq\vt'\Hab\vT')\;\ve)}} \\
338& \MO{Tactic'} & \Gamma & (\vf\;\va) &
351& \MO{Tactic'} & \Gamma & (\vf\;\va) &
339−\MoRet{\MO{Return}\;(\MO{Tactic'}\;\Gamma\;\vf)\; (\MO{Tactic'}\;\Gamma\;\va)}\\
352+\MoRet{\RW{return}\;(\MO{Tactic'}\;\Gamma\;\vf)\; (\MO{Tactic'}\;\Gamma\;\va)}\\
340−& \MO{Tactic'} & \Gamma & \vt & \MoRet{\MO{Return}\;\vt}
353+& \MO{Tactic'} & \Gamma & \vt & \MoRet{\RW{return}\;\vt}
@@ -385,7 +398,7 @@ resolve the existing problems with $\MO{ReUnify}$.
386(\tx=\te,\tp)\gets\PrimUnify\;\ve_1\;\ve_2\\
399(\tx=\te,\tp)\gets\PrimUnify\;\ve_1\;\ve_2\\
387\vec{\MO{Subst}}\;\tx\;\te\\
400\vec{\MO{Subst}}\;\tx\;\te\\
388−\MO{SubstProblems}\;(\tx=\te)\\
401+\MO{SubstProblems}\;\tx\;\te\\
389(\vC,\Delta,\VV{term},\tP,\vQ)\gets\MO{Get}\\
402(\vC,\Delta,\VV{term},\tP,\vQ)\gets\MO{Get}\\
390\vec{\MO{ReUnify}}\;\tP
403\vec{\MO{ReUnify}}\;\tP
@@ -395,7 +408,7 @@ resolve the existing problems with $\MO{ReUnify}$.
395\MO{ReUnify}\;(\Gamma,\ve_1,\ve_2)\;=\;\RW{do}\;\AR{
408\MO{ReUnify}\;(\Gamma,\ve_1,\ve_2)\;=\;\RW{do}\;\AR{
396(\tx=\te,\tp)\Gets\PrimUnify\;\ve_1\;\ve_2\\
409(\tx=\te,\tp)\Gets\PrimUnify\;\ve_1\;\ve_2\\
397\vec{\MO{Subst}}\;\tx\;\te\\
410\vec{\MO{Subst}}\;\tx\;\te\\
398−\MO{Return}\;\tp
411+\RW{return}\;\tp
@@ -413,14 +426,16 @@ keeping $\vx$ at the head:
414\PA{\A\A}{
427\PA{\A\A}{
415\MO{Claim}_\Gamma & (\vy \Hab\vS) & (\hole{\vx}{\vT}\SC\ve) &
428\MO{Claim}_\Gamma & (\vy \Hab\vS) & (\hole{\vx}{\vT}\SC\ve) &
429+ \MoRet{\RW{do}\;\AR{\MO{NewHole}\;\vy\\
416− \MoRet{\RW{return}\;\hole{\vx}{\vT}\SC\hole{\vy}{\vS}\SC\ve} \\
430+ \RW{return}\;\hole{\vx}{\vT}\SC\hole{\vy}{\vS}\SC\ve}} \\
420−An obvious difficulty is in ensuring that names are unique throughout a proof term.
434+An obvious difficulty is in ensuring that names are unique throughout a proof
421−The implementation ensures that any hole created by the $\MO{Claim}$ tactic
435+term. The implementation ensures that any hole created by the $\MO{NewHole}$
422−has a unique name by checking against existing names in scope and modifying
436+operation has a unique name by checking against existing names in scope and
423−the name if necessary. In this paper, we will assume that all created names are fresh.
437+modifying the name if necessary. In this paper, we will assume that all created
425The $\MO{Fill}$ tactic, given a value $\vv$, attempts to solve the current goal
440The $\MO{Fill}$ tactic, given a value $\vv$, attempts to solve the current goal
426with $\vv$, creating a guess binding in its place. $\MO{Fill}$ attempts to
441with $\vv$, creating a guess binding in its place. $\MO{Fill}$ attempts to
@@ -474,12 +489,14 @@ Therefore the resulting proof term is:
475The $\MO{Solve}$ tactic operates on a guess binding. If the guess is \remph{pure}, i.e., it
490The $\MO{Solve}$ tactic operates on a guess binding. If the guess is \remph{pure}, i.e., it
476is a \TT{} term containing no hole or guess bindings, then the value attached to
491is 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
481\MO{Solve}_\Gamma & (\guess{\vx}{\vT}{\vv}\SC\ve) &
497\MO{Solve}_\Gamma & (\guess{\vx}{\vT}{\vv}\SC\ve) &
498+ \MoRet{\RW{do}\;\AR{\MO{RemoveHole}\\
482− \MoRet{\RW{return}\;\ve[\vv/\vx]\hg\mbox{(if $\MO{Pure}\;\vv$)}}
499+ \RW{return}\;\ve[\vv/\vx]\hg\mbox{(if $\MO{Pure}\;\vv$)}}}
@@ -523,13 +540,15 @@ binding requires that the goal normalises to a function type:
526−Creating a $\forall$ binding requires that the goal is a $\TC{Type}$:
543+Creating a $\forall$ binding requires that the goal type converts
529\PA{\A\A}{
547\PA{\A\A}{
530\MO{Pi}_\Gamma & (\vn\Hab\vS) & (\hole{\vx}{\Type}\SC\vx) &
548\MO{Pi}_\Gamma & (\vn\Hab\vS) & (\hole{\vx}{\Type}\SC\vx) &
531 \MoRet{\RW{do}\;\AR{
549 \MoRet{\RW{do}\;\AR{
532− \Type\;\leftarrow\;\Check\;\vS\\
550+ \vV\;\leftarrow\;\Check\;\vS\\
551+ \MO{Convert}_\Gamma\;\vV\;\Type\\
533 \RW{return}\;\all{\vn}{\vS}\SC\hole{\vx}{\Type}\SC\vx
552 \RW{return}\;\all{\vn}{\vS}\SC\hole{\vx}{\Type}\SC\vx
@@ -543,7 +562,8 @@ Creating a $\LET$ binding requires a type and a value.
543\PA{\A\A}{
562\PA{\A\A}{
544\MO{Let}_\Gamma & (\vn\Hab\vS\defq\vv) & (\hole{\vx}{\vT}\SC\vx) &
563\MO{Let}_\Gamma & (\vn\Hab\vS\defq\vv) & (\hole{\vx}{\vT}\SC\vx) &
545 \MoRet{\RW{do}\;\AR{
564 \MoRet{\RW{do}\;\AR{
546− \Type\;\leftarrow\;\Check\;\vS\\
565+ \vV\;\leftarrow\;\Check\;\vS\\
566+ \MO{Convert}_\Gamma\;\vV\;\Type\\
547 \vS'\;\leftarrow\;\Check\;\vv\\
567 \vS'\;\leftarrow\;\Check\;\vv\\
548 \Unify\;\vS\;\vS'\\
568 \Unify\;\vS\;\vS'\\
549 \RW{return}\;\LET\;\vn\Hab\vS\defq\vv\SC\hole{\vx}{\vT}\SC\vx
569 \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}$
798and $\MO{Solve}$ is closed with a $\MO{Solve}$).
818and $\MO{Solve}$ is closed with a $\MO{Solve}$).
800Setting up elaboration in this way, with a proof state captured in a monad,
820Setting up elaboration in this way, with a proof state captured in a monad,
801−and a primitive collection of tactics,
821+and a primitive collection of tactics, makes it easy to derive more complex
802−makes it easy to derive more complex tactics for elaborating higher level language constructs,
822+tactics for elaborating higher level language constructs, in much the same way
803−in much the same way as the \texttt{Ltac} language in Coq. As a result, the
823+as the \texttt{Ltac} language in Coq~\cite{Delahaye2000}. As a result, the
804−description of elaboration of
824+description of elaboration of a language construct (or a program such as
805−a language construct (or a program such as $\FN{id}$) bears a strong resemblance to
825+$\FN{id}$) bears a strong resemblance to
806a Coq proof script.
826a Coq proof script.
@@ -865,11 +885,9 @@ The system state is a tuple, $(\vC,\vA,\vI)$, containing:
865\item Type class information, $\vI$, containing method signatures and dictionaries for type classes
885\item Type class information, $\vI$, containing method signatures and dictionaries for type classes
866\end{itemize}
886\end{itemize}
868−In the implementation, the system state is captured in a monad, \texttt{Idris}.
888+In the implementation, the system state is captured in a monad, \texttt{Idris},
869−This monad includes additional information such as syntax overloadings,
889+which includes additional information such as syntax overloadings, command line
870−command line options, and optimisations, which do not concern us here. Elaboration
890+options, and optimisations, which do not concern us here.
871−of expressions requires access to the system state in particular in order to expand
872−implicit arguments and resolve type classes.
874For each global name, $\vA$ records whether its arguments are explicit, implicit,
892For each global name, $\vA$ records whether its arguments are explicit, implicit,
875or type class constraints. For example, recall the declaration
893or 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
996elaboration of expressions. \IdrisM{} expression syntax is given in Figure
1014elaboration of expressions. \IdrisM{} expression syntax is given in Figure
997\ref{idrism} and declaration syntax given in Figure \ref{idrismd}.
1015\ref{idrism} and declaration syntax given in Figure \ref{idrismd}.
998\IdrisM{} is a subset of \Idris{} without syntactic sugar --- that is, without
1016\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
1000arguments in types bound explicitly
1018arguments in types bound explicitly
1001(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\;\va\;\vn$
1019(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\;\va\;\vn$
1002instead of simply $\Vect\;\va\;\vn$).
1020instead of simply $\Vect\;\va\;\vn$).
@@ -1147,7 +1165,9 @@ $\vV$ and $\vX$.
1147\ttinterp{\ve}
1165\ttinterp{\ve}
1150−\subsubsection{Elaborating applications}
1168+\subsubsection{Elaborating Applications}
1170+\label{sect:elabapps}
1152There are two cases to consider when elaborating applications:
1172There are two cases to consider when elaborating applications:
@@ -1200,17 +1220,21 @@ Finally, any type class instance arguments are resolved with the
1200built-in $\MO{Instance}$ tactic.
1220built-in $\MO{Instance}$ tactic.
1203−\ttinterp{\vx\;\ta}\;\mq\;
1224+\ttinterp{\vx\;\ta}\;\mq\;
1205\RW{do}\;
1225\RW{do}\;
1207(\tn,\tv)\;\gets\;\MO{Expand}\;\vx\;\ta\\
1227(\tn,\tv)\;\gets\;\MO{Expand}\;\vx\;\ta\\
1208\vec{\MO{Claim}}\;(\tn\Hab\tT)\\
1228\vec{\MO{Claim}}\;(\tn\Hab\tT)\\
1209\MO{Fill}\;\vx\;\tn\\
1229\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$)}\\
1211\MO{Solve} \\
1231\MO{Solve} \\
1212\vec{\MO{Instance}}\;\tn\hg\mbox{(for type class constraint argument $\vn$)}
1232\vec{\MO{Instance}}\;\tn\hg\mbox{(for type class constraint argument $\vn$)}
1236+\MO{ElabArg}\;\vn\;\vv\;\mq\;
1237+\MO{Focus}\;\vn;\;\ttinterp{\vv}
@@ -1220,10 +1244,10 @@ context, then recursively searches the global context. $\MO{Instance}$ is covere
1220in detail in Section \ref{sect:instance}.
1244in detail in Section \ref{sect:instance}.
1222To elaborate a simple function application, of an arbitrary expression to an
1246To elaborate a simple function application, of an arbitrary expression to an
1223−arbitrary argument, we need not worry about implicit arguments or class
1247+arbitrary argument (possibly with a dependent type), we need not worry about
1224−constraints. Instead, the function and argument are elaborated, and the results
1248+implicit arguments or class constraints. Instead, the function and argument are
1225−applied. Since elaboration is type directed, however, there must be an
1249+elaborated, and the results applied. Since elaboration is type directed,
1226−appropriate type for the function.
1250+however, there must be an appropriate type for the function.
1229\ttinterp{\ve\;\va}\;\mq\;\RW{do}\;
1253\ttinterp{\ve\;\va}\;\mq\;\RW{do}\;
@@ -1446,24 +1470,25 @@ ftest' n False x = ...
1447\noindent
1471\noindent
1448Elaboration of \texttt{with} builds the type declaration and auxiliary function
1472Elaboration of \texttt{with} builds the type declaration and auxiliary function
1449−automatically. It checks the left hand side, resulting in a set of patterns
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
1450−$\tp$, then splits these patterns into those necessary to type
1475+$\tp$ are then split into those necessary to type $\vW$, and the rest ($\tp_w$
1451−$\vW$, and the rest ($\tp_w$ and $\tp_n$ respectively) using
1476+and $\tp_n$ respectively) using
1452$\MO{SplitContext}$. Then, it builds a new declaration, abstracting over
1477$\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$.
1454$\MO{Abstract}\;\ve\;\vw\;\vp$ simply replaces any occurrence of $\vw$ in
1479$\MO{Abstract}\;\ve\;\vw\;\vp$ simply replaces any occurrence of $\vw$ in
1455$\vp$ with the name $\ve$.
1480$\vp$ with the name $\ve$.
1459−\MO{ElabClause}\;(\vx\;\ttt\;\iwith\;\ve\;\vec{\VV{pclause}})\;\mq\\
1484+\MO{ElabClause}\;(\vx\;\ttt\;\iwith\;\vw\;\vec{\VV{pclause}})\;\mq\\
1460\hg\hg\edo{
1485\hg\hg\edo{
1461\MO{NewProof}\;\TC{Infer};\;
1486\MO{NewProof}\;\TC{Infer};\;
1462\ttinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
1487\ttinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
1463\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
1488\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
1464\tp\gets\MO{Patterns}\\
1489\tp\gets\MO{Patterns}\\
1465\MO{NewTerm}\;\TC{Infer};\;
1490\MO{NewTerm}\;\TC{Infer};\;
1466−\ttinterp{\DC{MkInfer}\;\_\;\ve}\\
1491+\ttinterp{\DC{MkInfer}\;\_\;\vw}\\
1467\DC{MkInfer}\;\vW\;\vw'\gets\MO{Term}\\
1492\DC{MkInfer}\;\vW\;\vw'\gets\MO{Term}\\
1468(\tp_w,\tp_n)\;\gets\;\MO{SplitContext}\;\vW\;\tp\\
1493(\tp_w,\tp_n)\;\gets\;\MO{SplitContext}\;\vW\;\tp\\
1469\MO{TTDecl}\;(\vx'\Hab\tp_{w}\to(\ve\Hab\vW)\to\vec{\MO{Abstract}}\;\ve\;\vw'\;\tp_{n}\to\vT)\\
1494\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
1508of the functions in the class, and an instance is simply an instance of the
1533of the functions in the class, and an instance is simply an instance of the
1509record. The methods are translated to top level functions which extract the
1534record. The methods are translated to top level functions which extract the
1510relevant function from the dictionary. For example, for the \texttt{Show} type
1535relevant 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)
1513\begin{SaveVerbatim}{showdata}
1540\begin{SaveVerbatim}{showdata}
@@ -1670,8 +1697,9 @@ constructing programs in \TT{}.
1670\label{sect:instance}
1697\label{sect:instance}
1672When elaborating applications, recall that implicit arguments are filled in by
1699When elaborating applications, recall that implicit arguments are filled in by
1700+unification as described in Section \ref{sect:elabapps}, and type class
1673−unification, and type class constraints by an $\MO{Instance}$ tactic which searches
1701+constraints by an $\MO{Instance}$ tactic which searches the context for an
1674−the context for an instance of the required type class.
1702+instance of the required type class.
1676The $\MO{Instance}$ tactic begins by trying to find a solution in the local context,
1704The $\MO{Instance}$ tactic begins by trying to find a solution in the local context,
1677using the $\MO{Trivial}$ tactic, which attempts
1705using the $\MO{Trivial}$ tactic, which attempts
@@ -1788,9 +1816,9 @@ the vector append function, containing a metavariable \texttt{append\_rec}:
1789\begin{SaveVerbatim}{vappmv}
1817\begin{SaveVerbatim}{vappmv}
1791−(++) : Vect A n -> Vect A m -> Vect A (n + m)
1819+(++) : Vect a n -> Vect a m -> Vect a (n + m)
1792−(++) Nil ys = ys
1820+Nil ++ ys = ys
1793−(++) (x :: xs) ys = x :: ?append_rec
1821+(x :: xs) ++ ys = x :: ?append_rec
1795\end{SaveVerbatim}
1823\end{SaveVerbatim}
1796\useverb{vappmv}
1824\useverb{vappmv}
@@ -1862,10 +1890,11 @@ lookup_default_case i xs def (Just x) = x
1862\end{SaveVerbatim}
1890\end{SaveVerbatim}
1863\useverb{listlookupmv}
1891\useverb{listlookupmv}
1865−To elaborate a $\icase$ expression involves \texttt{let} binding the scrutinee of
1893+To elaborate a $\icase$ expression involves \texttt{let} binding the scrutinee
1894+of the $\icase$ expression, introducing a new name $\VV{scrutinee}$, and
1866−the $\icase$ expression and creating a metavariable $\VV{xcase}$ to implement the
1895+creating a metavariable $\VV{xcase}$ to implement the pattern matching. Then
1867−pattern matching. Then the elaborator builds a new pattern matching definition for $\VV{xcase}$
1896+the elaborator builds a new pattern matching definition for $\VV{xcase}$ and
1868−and elaborate it:
1897+elaborates it: