@@ -1,11 +1,79 @@
1\section{Miscellany}
1\section{Miscellany}
3In this section we discuss a variety of additional features: extensible syntax,
3In this section we discuss a variety of additional features: extensible syntax,
4+auto implicit and default
4−literate programming, interfacing with external libraries through the
5+arguments, literate programming, interfacing with external libraries through the
5foriegn function interface, and the universe hierarchy.
6foriegn function interface, and the universe hierarchy.
7\input{syntax}
8\input{syntax}
10+\subsection{Auto implicit arguments}
12+We have already seen implicit arguments, which allows arguments to be omitted when
13+they can be inferred by the type checker, e.g.
15+\useverb{vlookupimpty}
18+In other situations, it may be possible to infer arguments not by type checking but
19+by searching the context for an appropriate value, or constructing a proof. For example,
20+the following definition of \texttt{head} which requires a proof that the list is
23+\begin{SaveVerbatim}{safehead}
25+isCons : List a -> Bool
27+isCons (x :: xs) = True
29+head : (xs : List a) -> (isCons xs = True) -> a
36+If the list is statically known to be non-empty, either because its value is known or
37+because a proof already exists in the context, the proof can be constructed
38+automatically. Auto implicit arguments allow this to happen silently. We define
39+\texttt{head} as follows:
41+\begin{SaveVerbatim}{headauto}
43+head : (xs : List a) -> {auto p : isCons xs = True} -> a
50+The \texttt{auto} annotation on the implicit argument means that \Idris{} will
51+attempt to fill in the implicit argument using the \texttt{trivial} tactic, which
52+searches through the context for a proof, and tries to solve with \texttt{refl}
53+if a proof is not found.
54+Now when \texttt{head} is applied, the proof can be omitted. In the case that a proof
55+is not found, it can be provided explicitly as normal:
57+\begin{SaveVerbatim}{headapp}
59+head xs {p = ?headProof}
65+More generally, we can fill in implicit arguments with a default value by annotating
66+them with \texttt{default}. The definition above is equivalent to:
68+\begin{SaveVerbatim}{defimp}
70+head : (xs : List a) ->
71+ {default proof { trivial; } p : isCons xs = True} -> a
9\subsection{Literate programming}
77\subsection{Literate programming}
11Like Haskell, \Idris{} supports \emph{literate} programming. If a file has an
79Like Haskell, \Idris{} supports \emph{literate} programming. If a file has an