@@ -8,23 +8,23 @@
9An \Idris{} program consists of a series of declarations --- data types,
9An \Idris{} program consists of a series of declarations --- data types,
10functions, classes and instances. In this section, we describe how these
10functions, classes and instances. In this section, we describe how these
11−high level declarations are translated into a \TT{} program consisting of
11+high-level declarations are translated into a \TT{} program consisting of
12inductive families and pattern matching function definitions. We will need to
12inductive families and pattern matching function definitions. We will need to
13work at the \remph{declaration} level, and at the \remph{expression} level,
13work at the \remph{declaration} level, and at the \remph{expression} level,
14defining the following meta-operations.
14defining the following meta-operations.
16\begin{itemize}
16\begin{itemize}
17\item $\ttinterp{\cdot}$, which builds a \TT{} expression from an \Idris{} expression.
17\item $\ttinterp{\cdot}$, which builds a \TT{} expression from an \Idris{} expression.
18−\item $\MO{Elab}$, which processes a top level \Idris{} declaration by generating
18+\item $\MO{Elab}$, which processes a top-level \Idris{} declaration by generating
19one or more \TT{} declarations.
19one or more \TT{} declarations.
20−\item $\MO{TTDecl}$, which adds a top level \TT{} declaration.
20+\item $\MO{TTDecl}$, which adds a top-level \TT{} declaration.
21\end{itemize}
21\end{itemize}
24\subsection{The Development Calculus \TTdev}
24\subsection{The Development Calculus \TTdev}
26−\TT{} expressions are built by using high level \Idris{} expressions to
26+\TT{} expressions are built by using high-level \Idris{} expressions to
27−direct a tactic based theorem prover, which builds the \TT{} expressions
27+direct a tactic-based theorem prover, which builds the \TT{} expressions
28step by step, by refinement. In order to build expressions in this way,
28step by step, by refinement. In order to build expressions in this way,
29the type theory needs to support
29the type theory needs to support
30\remph{incomplete} terms, and a method for term construction.
30\remph{incomplete} terms, and a method for term construction.
@@ -40,7 +40,7 @@ These extensions are given in Figure \ref{ttdev}.
40The \remph{guess} binding is
40The \remph{guess} binding is
41similar to a $\LET$ binding, but without any computational force,
41similar to a $\LET$ binding, but without any computational force,
42i.e. there are no reduction rules for guess bindings.
42i.e. there are no reduction rules for guess bindings.
43−Using binders to represent holes is useful in a dependently typed setting since
43+Using binders to represent holes is useful in a dependently-typed setting since
44one value may determine another. Attaching a guess to a binder ensures that
44one value may determine another. Attaching a guess to a binder ensures that
45instantiating one such variable also instantiates all of its dependencies.
45instantiating one such variable also instantiates all of its dependencies.
@@ -87,12 +87,11 @@ instantiating one such variable also instantiates all of its dependencies.
88\label{sect:prfstate}
88\label{sect:prfstate}
90−We will build expressions in \TT{} from high level \Idris{} expressions by
90+We will build expressions in \TT{} from high-level \Idris{} expressions by
91−creating a top level hole binding with the appropriate type, and refining it
91+creating a top-level hole binding with the appropriate type, and refining it
92according to the structure of the \Idris{} expression. Noting the Curry-Howard
92according to the structure of the \Idris{} expression. Noting the Curry-Howard
93correspondence between programs and proofs, and the relationship between our
93correspondence between programs and proofs, and the relationship between our
94−method for elaboration and tactic
95−based theorem proving, we refer to a development as a \emph{proof}.
94+method for elaboration and tactic-based theorem proving, we refer to a development as a \emph{proof}.
96A proof state is a tuple, $(\vC, \Delta, \ve, \vP, \vQ)$, containing:
95A proof state is a tuple, $(\vC, \Delta, \ve, \vP, \vQ)$, containing:
98\begin{itemize}
97\begin{itemize}
@@ -118,7 +117,7 @@ When the hole queue is empty, and there are no remaining unification
118problems, the proof term is complete.
117problems, the proof term is complete.
120Creating a \TT{} expression from an \Idris{} expression involves creating
119Creating a \TT{} expression from an \Idris{} expression involves creating
121−a new proof state, with an empty proof term, and using the high level definition
120+a new proof state, with an empty proof term, and using the high-level definition
122to direct the building of a final proof state, with a complete proof term.
121to direct the building of a final proof state, with a complete proof term.
124In the implementation, the proof state is captured in an elaboration monad,
123In the implementation, the proof state is captured in an elaboration monad,
@@ -890,7 +889,7 @@ a Coq proof script.
891\label{sect:sysstate}
890\label{sect:sysstate}
893−To elaborate \Idris{} programs we will build expressions from high level
892+To elaborate \Idris{} programs we will build expressions from high-level
894declarations of functions, data types and classes, and add the resulting
893declarations of functions, data types and classes, and add the resulting
895definitions to a global system state.
894definitions to a global system state.
896The system state is a tuple, $(\vC,\vA,\vI)$, containing:
895The system state is a tuple, $(\vC,\vA,\vI)$, containing:
@@ -1035,7 +1034,7 @@ arguments in types bound explicitly
1035(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\;\vn\;\va$
1034(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\;\vn\;\va$
1036instead of simply $\Vect\;\vn\;\va$).
1035instead of simply $\Vect\;\vn\;\va$).
1037Note that we separate implicit and type constraint bindings, to ensure that they
1036Note that we separate implicit and type constraint bindings, to ensure that they
1038−only appear in top level declarations.
1037+only appear in top-level declarations.
1039It is in general straightforward to
1038It is in general straightforward to
1040convert full \Idris{} to \IdrisM{} --- syntactic sugar is implemented by a
1039convert full \Idris{} to \IdrisM{} --- syntactic sugar is implemented by a
1041direct source transformation, and implicit arguments can be identified as the names
1040direct source transformation, and implicit arguments can be identified as the names
@@ -1091,10 +1090,7 @@ elaboration will fail.
1091If we are building the left hand side of a pattern clause, however, there is a
1090If we are building the left hand side of a pattern clause, however, there is a
1092problem, as it is the left hand side which \remph{defines} variables. In this
1091problem, as it is the left hand side which \remph{defines} variables. In this
1093context, we assume that attempting to elaborate a variable which does not type
1092context, we assume that attempting to elaborate a variable which does not type
1094−check means that the variable is a pattern variable\footnote{In Haskell,
1093+check means that the variable is a pattern variable:
1095−pattern variables are all lower case, so type checking can assume that a
1096−lower case name in a pattern refers to a variable. In \Idris{} however, a
1097−name in a pattern may refer to a function, if forced by some dependency.}:
1100\ttpinterp{\vx}\;\mq\;
1096\ttpinterp{\vx}\;\mq\;
@@ -1103,6 +1099,11 @@ name in a pattern may refer to a function, if forced by some dependency.}:
1102+In Haskell, for comparison,
1103+pattern variables are all lower case, so type checking can assume that a
1104+lower case name in a pattern refers to a variable. In \Idris{} however, a
1105+name in a pattern may refer to a function, if forced by some dependency.
1106We also need to elaborate \remph{placeholders}, which are subexpressions we expect to
1107We also need to elaborate \remph{placeholders}, which are subexpressions we expect to
1107solve by unification. In this case, we simply move on to the next hole in the queue, moving
1108solve by unification. In this case, we simply move on to the next hole in the queue, moving
1108the current hole to the end of the queue with $\MO{Unfocus}$:
1109the current hole to the end of the queue with $\MO{Unfocus}$:
@@ -1425,14 +1426,14 @@ the right hand side $\ve$ to use the lifted definitions, rather than the origina
1425\subsubsection{Elaborating the \texttt{with} rule}
1426\subsubsection{Elaborating the \texttt{with} rule}
1427The \texttt{with} rule allows \remph{dependent} pattern matching on intermediate values.
1428The \texttt{with} rule allows \remph{dependent} pattern matching on intermediate values.
1428−Translating this into \TT{} involves constructing an auxiliary top level
1429+Translating this into \TT{} involves constructing an auxiliary top-level
1429definition for
1430definition for
1430the intermediate pattern match. For example, recall \tFN{natToBin}:
1431the intermediate pattern match. For example, recall \tFN{natToBin}:
1432\useverb{natToBin}
1433\useverb{natToBin}
1434\noindent
1435\noindent
1435−This is equivalent to the following, using top level definitions only:
1436+This is equivalent to the following, using top-level definitions only:
1437\begin{SaveVerbatim}{natToBinw}
1438\begin{SaveVerbatim}{natToBinw}
@@ -1454,8 +1455,10 @@ natToBin' (S (j + j)) odd = True :: natToBin j
1455\noindent
1456\noindent
1456Additionally, the elaborator abstracts over the term being analysed in the type
1457Additionally, the elaborator abstracts over the term being analysed in the type
1457−of the generated auxiliary definition\footnote{This is sometimes referred to
1458+of the generated auxiliary definition
1459+%\footnote{This is sometimes referred to
1460+%as ``magic \texttt{with}''.}
1458−as ``magic \texttt{with}''.} and reorders the arguments as required.
1461+and reorders the arguments as required.
1459For example:
1462For example:
1461\begin{SaveVerbatim}{magicwith}
1464\begin{SaveVerbatim}{magicwith}
@@ -1533,7 +1536,7 @@ A $\iwith$ block in a clause for $\vx$
1533results in an auxiliary definition $\vx'$, where $\vx'$ is a fresh name,
1536results in an auxiliary definition $\vx'$, where $\vx'$ is a fresh name,
1534which takes an extra argument corresponding to the intermediate result which
1537which takes an extra argument corresponding to the intermediate result which
1535is to be matched.
1538is to be matched.
1536−$\MO{MatchWith}$ matches the left hand side of the top level definition against
1539+$\MO{MatchWith}$ matches the left hand side of the top-level definition against
1537each $\VV{pclause}$, using the result of the match to build each pattern clause
1540each $\VV{pclause}$, using the result of the match to build each pattern clause
1538for $\vx'$.
1541for $\vx'$.
1539The clauses in the with block must be of a specific form: they must have an initial
1542The clauses in the with block must be of a specific form: they must have an initial
@@ -1554,7 +1557,7 @@ Classes are implemented as dictionaries of functions for each instance,
1554following the implementation of first class type classes in Coq~\cite{Sozeau2008}.
1557following the implementation of first class type classes in Coq~\cite{Sozeau2008}.
1555Therefore, a class declaration elaborates to a record type containing all
1558Therefore, a class declaration elaborates to a record type containing all
1556of the functions in the class, and an instance is simply an instance of the
1559of the functions in the class, and an instance is simply an instance of the
1557−record. The methods are translated to top level functions which extract the
1560+record. The methods are translated to top-level functions which extract the
1558relevant function from the dictionary. For example, for the \texttt{Show}
1561relevant function from the dictionary. For example, for the \texttt{Show}
1559class, the \texttt{class} declaration is translated (in the elaborated code,
1562class, the \texttt{class} declaration is translated (in the elaborated code,
1560using the surface \Idris{} syntax for readability)
1563using the surface \Idris{} syntax for readability)
@@ -1585,7 +1588,7 @@ showNat = InstanceShow show' where
1585\end{SaveVerbatim}
1588\end{SaveVerbatim}
1586\useverb{shownatf}
1589\useverb{shownatf}
1588−The call to \tFN{show} in the body of the instance uses the top level \tFN{show}
1591+The call to \tFN{show} in the body of the instance uses the top-level \tFN{show}
1589function, with the instance resolved by the elaborator.
1592function, with the instance resolved by the elaborator.
1590Where instances have constraints, these constraints are passed on to
1593Where instances have constraints, these constraints are passed on to
1591the function declaration for the instance. For example, for \texttt{Show (List a)}:
1594the function declaration for the instance. For example, for \texttt{Show (List a)}:
@@ -1710,7 +1713,7 @@ defined instance:
1710Adding default definitions is straightforward: simply insert the default definition where
1713Adding default definitions is straightforward: simply insert the default definition where
1711there is a method missing in an \texttt{instance} declaration.
1714there is a method missing in an \texttt{instance} declaration.
1713−\textbf{Remark:} Here, we have added a higher level language construct
1716+Here, we have added a higher level language construct
1714(classes) simply by elaborating in terms of lower level language constructs
1717(classes) simply by elaborating in terms of lower level language constructs
1715(data types and functions). We achieve type class resolution by implementing a
1718(data types and functions). We achieve type class resolution by implementing a
1716tactic, $\MO{Instance}$. We can build several extensions this way because we
1719tactic, $\MO{Instance}$. We can build several extensions this way because we
@@ -1814,8 +1817,8 @@ dependent pattern matching definitions and expansion of implicit arguments
1814and classes. In order to make the language truly general purpose, however, we
1817and classes. In order to make the language truly general purpose, however, we
1815will need to add higher level extensions. Full \Idris{} is \IdrisM{} extended
1818will need to add higher level extensions. Full \Idris{} is \IdrisM{} extended
1816with \texttt{do}-notation, idiom brackets~\cite{McBride2007}, \texttt{case} expressions,
1819with \texttt{do}-notation, idiom brackets~\cite{McBride2007}, \texttt{case} expressions,
1817−pattern matching \texttt{let}, metavariables and tactic based theorem proving.
1820+pattern matching \texttt{let}, metavariables and tactic-based theorem proving.
1818−The majority of these extensions are straightforward transformations of high level
1821+The majority of these extensions are straightforward transformations of high-level
1819\Idris{} programs --- for example, \texttt{do}-notation can be reduced directly to
1822\Idris{} programs --- for example, \texttt{do}-notation can be reduced directly to
1820\IdrisM{} function applications. Some, however, require further support. In this section,
1823\IdrisM{} function applications. Some, however, require further support. In this section,
1821we complete the presentation of \IdrisM{} by extending it with metavariables
1824we complete the presentation of \IdrisM{} by extending it with metavariables
@@ -1877,7 +1880,7 @@ append_rec a m n x xs ys = app xs ys
1877\end{SaveVerbatim}
1880\end{SaveVerbatim}
1878\useverb{appendrec_def}
1881\useverb{appendrec_def}
1880−Elaborating a metavariable involves adding a new top level definition which is applied
1883+Elaborating a metavariable involves adding a new top-level definition which is applied
1881to all of the variables in local scope.
1884to all of the variables in local scope.
@@ -1894,8 +1897,8 @@ to all of the variables in local scope.
1895A \texttt{case} expression allows pattern matching on intermediate values. The difficulty
1898A \texttt{case} expression allows pattern matching on intermediate values. The difficulty
1896in elaborating \texttt{case} expressions is that \TT{} allows matching only on
1899in elaborating \texttt{case} expressions is that \TT{} allows matching only on
1897−\emph{top level} values. Elaborating a \texttt{case} expression, therefore,
1900+\emph{top-level} values. Elaborating a \texttt{case} expression, therefore,
1898−involves creating a new top level function standing for the expression, and applying it.
1901+involves creating a new top-level function standing for the expression, and applying it.
1899The natural
1902The natural
1900way to implement this is to use a metavariable. For example, we have already seen
1903way to implement this is to use a metavariable. For example, we have already seen
1901\texttt{lookup\_default}:
1904\texttt{lookup\_default}: