doc-src/TutorialI/Misc/document/pairs.tex
author nipkow
Wed, 29 Nov 2000 17:23:27 +0100
changeset 10539 5929460a41df
parent 10538 d1bf9ca9008d
child 10543 8e4307d1207a
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9722
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     1
%
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     2
\begin{isabellebody}%
9924
3370f6aa3200 updated;
wenzelm
parents: 9792
diff changeset
     3
\def\isabellecontext{pairs}%
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     4
%
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     5
\begin{isamarkuptext}%
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
     6
\label{sec:pairs}\indexbold{product type}
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
     7
\index{pair|see{product type}}\index{tuple|see{product type}}
9933
9feb1e0c4cb3 *** empty log message ***
nipkow
parents: 9924
diff changeset
     8
HOL also has pairs: \isa{($a@1$,$a@2$)} is of type $\tau@1$
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
     9
\indexboldpos{\isasymtimes}{$Isatype} $\tau@2$ provided each $a@i$ is of type
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
    10
$\tau@i$. The components of a pair are extracted by \isaindexbold{fst} and
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
    11
\isaindexbold{snd}:
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
    12
 \isa{fst($x$,$y$) = $x$} and \isa{snd($x$,$y$) = $y$}. Tuples
9933
9feb1e0c4cb3 *** empty log message ***
nipkow
parents: 9924
diff changeset
    13
are simulated by pairs nested to the right: \isa{($a@1$,$a@2$,$a@3$)} stands
9feb1e0c4cb3 *** empty log message ***
nipkow
parents: 9924
diff changeset
    14
for \isa{($a@1$,($a@2$,$a@3$))} and $\tau@1 \times \tau@2 \times \tau@3$ for
9feb1e0c4cb3 *** empty log message ***
nipkow
parents: 9924
diff changeset
    15
$\tau@1 \times (\tau@2 \times \tau@3)$. Therefore we have
9feb1e0c4cb3 *** empty log message ***
nipkow
parents: 9924
diff changeset
    16
\isa{fst(snd($a@1$,$a@2$,$a@3$)) = $a@2$}.
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    17
10539
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    18
Remarks:
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    19
\begin{itemize}
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    20
\item
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
    21
There is also the type \isaindexbold{unit}, which contains exactly one
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
    22
element denoted by \ttindexboldpos{()}{$Isatype}. This type can be viewed
10539
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    23
as a degenerate product with 0 components.
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    24
\item
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    25
Products, like type \isa{nat}, are datatypes, which means
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
    26
in particular that \isa{induct{\isacharunderscore}tac} and \isa{case{\isacharunderscore}tac} are applicable to
10539
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    27
terms of product type.
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    28
\item
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10187
diff changeset
    29
Instead of tuples with many components (where ``many'' is not much above 2),
10539
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    30
it is preferable to use records.
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    31
\end{itemize}
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
    32
For more information on pairs and records see Chapter~\ref{ch:more-types}.%
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    33
\end{isamarkuptext}%
9722
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
    34
\end{isabellebody}%
9145
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    35
%%% Local Variables:
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    36
%%% mode: latex
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    37
%%% TeX-master: "root"
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    38
%%% End: