9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
9924
|
3 |
\def\isabellecontext{pairs}%
|
9541
|
4 |
%
|
|
5 |
\begin{isamarkuptext}%
|
10538
|
6 |
\label{sec:pairs}\indexbold{product type}
|
|
7 |
\index{pair|see{product type}}\index{tuple|see{product type}}
|
9933
|
8 |
HOL also has 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
|
|
10 |
$\tau@i$. The components of a pair are extracted by \isaindexbold{fst} and
|
|
11 |
\isaindexbold{snd}:
|
|
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
|
10538
|
21 |
There is also the type \isaindexbold{unit}, which contains exactly one
|
|
22 |
element denoted by \ttindexboldpos{()}{$Isatype}. 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.
|
|
28 |
\item
|
10538
|
29 |
Instead of tuples with many components (where ``many'' is not much above 2),
|
10539
|
30 |
it is preferable to use records.
|
|
31 |
\end{itemize}
|
|
32 |
For more information on pairs and records see Chapter~\ref{ch:more-types}.%
|
9541
|
33 |
\end{isamarkuptext}%
|
9722
|
34 |
\end{isabellebody}%
|
9145
|
35 |
%%% Local Variables:
|
|
36 |
%%% mode: latex
|
|
37 |
%%% TeX-master: "root"
|
|
38 |
%%% End:
|