@@ -109,6 +109,10 @@ e.g. (::). Infix operators can use any of the symbols:
109\end{SaveVerbatim}
109\end{SaveVerbatim}
110\useverb{infixsyms}
110\useverb{infixsyms}
112+\begin{SaveVerbatim}{argh}
112\subsection{Functions}
116\subsection{Functions}
114Functions are implemented by pattern matching, again using a similar syntax to
118Functions are implemented by pattern matching, again using a similar syntax to
@@ -196,6 +200,34 @@ rev xs = revAcc [] xs where {
196Any names which are visible in the outer scope are also visible in the \texttt{where}
200Any names which are visible in the outer scope are also visible in the \texttt{where}
197clause (unless they have been redefined, such as \texttt{xs} here).
201clause (unless they have been redefined, such as \texttt{xs} here).
203+\subsubsection*{\texttt{let} bindings}
205+Intermediate values can be calculated using \texttt{let} bindings:
207+\begin{SaveVerbatim}{letb}
209+mirror : List a -> List a;
210+mirror xs = let xs' = rev xs in
217+We can do simple pattern matching in \texttt{let} bindings too. For example, we can extract
218+fields from a record as follows, as well as by pattern matching at the top level:
220+\begin{SaveVerbatim}{letp}
222+data Person = MkPerson String Int;
224+showPerson : Person -> String;
225+showPerson p = let MkPerson name age = p in
226+ name ++ " is " ++ show age ++ " years old";
199\subsection{Dependent Types}
231\subsection{Dependent Types}
201\subsubsection{Vectors}
233\subsubsection{Vectors}
@@ -625,12 +657,13 @@ to use an anonymous function:
625\end{SaveVerbatim}
657\end{SaveVerbatim}
626\useverb{lam1}
658\useverb{lam1}
628The notation \texttt{$\backslash$x => val} constructs an anonymous function
661The notation \texttt{$\backslash$x => val} constructs an anonymous function
629which takes one argument, \texttt{x} and returns the expression \texttt{val}.
662which takes one argument, \texttt{x} and returns the expression \texttt{val}.
630Anonymous functions may take several arguments, separated by commas, e.g.
663Anonymous functions may take several arguments, separated by commas, e.g.
631\texttt{$\backslash$x, y, z => val}. Arguments may also be given explicit
664\texttt{$\backslash$x, y, z => val}. Arguments may also be given explicit
632−types, e.g. \texttt{$\backslash$x : Int => x * 2}.
665+types, e.g. \texttt{$\backslash$x : Int => x * 2}, and can pattern match,
633−
666+e.g. \texttt{$\backslash$ (x, y) => x + y}.
634We could also use an operator section:
667We could also use an operator section:
636\begin{SaveVerbatim}{sec1}
669\begin{SaveVerbatim}{sec1}
@@ -641,6 +674,7 @@ We could also use an operator section:
641\end{SaveVerbatim}
674\end{SaveVerbatim}
642\useverb{sec1}
675\useverb{sec1}
644\texttt{(*2)} is shorthand for a function which multiplies a number by 2. It expands to
678\texttt{(*2)} is shorthand for a function which multiplies a number by 2. It expands to
645\texttt{$\backslash$x => x * 2}.
679\texttt{$\backslash$x => x * 2}.
646Similarly, \texttt{(2*)} would expand to \texttt{$\backslash$x => 2 * x}.
680Similarly, \texttt{(2*)} would expand to \texttt{$\backslash$x => 2 * x}.