9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
9924
|
3 |
\def\isabellecontext{pairs}%
|
11866
|
4 |
\isamarkupfalse%
|
9541
|
5 |
%
|
|
6 |
\begin{isamarkuptext}%
|
11428
|
7 |
\label{sec:pairs}\index{pairs and tuples}
|
|
8 |
HOL also has ordered pairs: \isa{($a@1$,$a@2$)} is of type $\tau@1$
|
10538
|
9 |
\indexboldpos{\isasymtimes}{$Isatype} $\tau@2$ provided each $a@i$ is of type
|
11428
|
10 |
$\tau@i$. The functions \cdx{fst} and
|
|
11 |
\cdx{snd} extract the components of a pair:
|
10538
|
12 |
\isa{fst($x$,$y$) = $x$} and \isa{snd($x$,$y$) = $y$}. Tuples
|
9933
|
13 |
are simulated by pairs nested to the right: \isa{($a@1$,$a@2$,$a@3$)} stands
|
|
14 |
for \isa{($a@1$,($a@2$,$a@3$))} and $\tau@1 \times \tau@2 \times \tau@3$ for
|
|
15 |
$\tau@1 \times (\tau@2 \times \tau@3)$. Therefore we have
|
|
16 |
\isa{fst(snd($a@1$,$a@2$,$a@3$)) = $a@2$}.
|
9541
|
17 |
|
10539
|
18 |
Remarks:
|
|
19 |
\begin{itemize}
|
|
20 |
\item
|
11428
|
21 |
There is also the type \tydx{unit}, which contains exactly one
|
11456
|
22 |
element denoted by~\cdx{()}. This type can be viewed
|
10539
|
23 |
as a degenerate product with 0 components.
|
|
24 |
\item
|
|
25 |
Products, like type \isa{nat}, are datatypes, which means
|
10538
|
26 |
in particular that \isa{induct{\isacharunderscore}tac} and \isa{case{\isacharunderscore}tac} are applicable to
|
10539
|
27 |
terms of product type.
|
10839
|
28 |
Both replace the term by a pair of variables.
|
10539
|
29 |
\item
|
10795
|
30 |
Tuples with more than two or three components become unwieldy;
|
|
31 |
records are preferable.
|
10539
|
32 |
\end{itemize}
|
|
33 |
For more information on pairs and records see Chapter~\ref{ch:more-types}.%
|
9541
|
34 |
\end{isamarkuptext}%
|
11866
|
35 |
\isamarkuptrue%
|
|
36 |
\isamarkupfalse%
|
9722
|
37 |
\end{isabellebody}%
|
9145
|
38 |
%%% Local Variables:
|
|
39 |
%%% mode: latex
|
|
40 |
%%% TeX-master: "root"
|
|
41 |
%%% End:
|