8749
|
1 |
\begin{isabelle}%
|
9541
|
2 |
%
|
|
3 |
\begin{isamarkuptext}%
|
|
4 |
HOL also has pairs: \isa{($a@1$,$a@2$)} is of type \isa{$\tau@1$ *
|
|
5 |
$\tau@2$} provided each $a@i$ is of type $\tau@i$. The components of a pair
|
|
6 |
are extracted by \isa{fst} and \isa{snd}: \isa{fst($x$,$y$) = $x$} and
|
|
7 |
\isa{snd($x$,$y$) = $y$}. Tuples are simulated by pairs nested to the right:
|
|
8 |
\isa{($a@1$,$a@2$,$a@3$)} stands for \isa{($a@1$,($a@2$,$a@3$))} and
|
|
9 |
\isa{$\tau@1$ * $\tau@2$ * $\tau@3$} for \isa{$\tau@1$ * ($\tau@2$ *
|
|
10 |
$\tau@3$)}. Therefore we have \isa{fst(snd($a@1$,$a@2$,$a@3$)) = $a@2$}.
|
|
11 |
|
|
12 |
It is possible to use (nested) tuples as patterns in abstractions, for
|
|
13 |
example \isa{\isasymlambda(x,y,z).x+y+z} and
|
|
14 |
\isa{\isasymlambda((x,y),z).x+y+z}.
|
|
15 |
In addition to explicit $\lambda$-abstractions, tuple patterns can be used in
|
|
16 |
most variable binding constructs. Typical examples are
|
|
17 |
\begin{quote}
|
|
18 |
\isa{let\ (x,\ y)\ =\ f\ z\ in\ (y,\ x)}\\
|
|
19 |
\isa{case\ xs\ of\ []\ {\isasymRightarrow}\ 0\ |\ (x,\ y)\ \#\ zs\ {\isasymRightarrow}\ x\ +\ y}
|
|
20 |
\end{quote}
|
|
21 |
Further important examples are quantifiers and sets (see~\S\ref{quant-pats}).%
|
|
22 |
\end{isamarkuptext}%
|
8749
|
23 |
\end{isabelle}%
|
9145
|
24 |
%%% Local Variables:
|
|
25 |
%%% mode: latex
|
|
26 |
%%% TeX-master: "root"
|
|
27 |
%%% End:
|