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