doc-src/TutorialI/Misc/pairs.thy
author paulson
Thu, 26 Jul 2001 16:43:02 +0200
changeset 11456 7eb63f63e6c6
parent 11428 332347b9b942
child 16417 9bc16273c2d4
permissions -rw-r--r--
revisions and indexing
nipkow@8745
     1
(*<*)
nipkow@8745
     2
theory pairs = Main:;
nipkow@9541
     3
(*>*)
paulson@11428
     4
text{*\label{sec:pairs}\index{pairs and tuples}
paulson@11428
     5
HOL also has ordered pairs: \isa{($a@1$,$a@2$)} is of type $\tau@1$
nipkow@10538
     6
\indexboldpos{\isasymtimes}{$Isatype} $\tau@2$ provided each $a@i$ is of type
paulson@11428
     7
$\tau@i$. The functions \cdx{fst} and
paulson@11428
     8
\cdx{snd} extract the components of a pair:
nipkow@10538
     9
 \isa{fst($x$,$y$) = $x$} and \isa{snd($x$,$y$) = $y$}. Tuples
nipkow@9933
    10
are simulated by pairs nested to the right: \isa{($a@1$,$a@2$,$a@3$)} stands
nipkow@9933
    11
for \isa{($a@1$,($a@2$,$a@3$))} and $\tau@1 \times \tau@2 \times \tau@3$ for
nipkow@9933
    12
$\tau@1 \times (\tau@2 \times \tau@3)$. Therefore we have
nipkow@9933
    13
\isa{fst(snd($a@1$,$a@2$,$a@3$)) = $a@2$}.
nipkow@9541
    14
nipkow@10539
    15
Remarks:
nipkow@10539
    16
\begin{itemize}
nipkow@10539
    17
\item
paulson@11428
    18
There is also the type \tydx{unit}, which contains exactly one
paulson@11456
    19
element denoted by~\cdx{()}.  This type can be viewed
nipkow@10539
    20
as a degenerate product with 0 components.
nipkow@10539
    21
\item
nipkow@10539
    22
Products, like type @{typ nat}, are datatypes, which means
nipkow@10538
    23
in particular that @{text induct_tac} and @{text case_tac} are applicable to
nipkow@10539
    24
terms of product type.
nipkow@10839
    25
Both replace the term by a pair of variables.
nipkow@10539
    26
\item
paulson@10795
    27
Tuples with more than two or three components become unwieldy;
paulson@10795
    28
records are preferable.
nipkow@10539
    29
\end{itemize}
nipkow@10539
    30
For more information on pairs and records see Chapter~\ref{ch:more-types}.
nipkow@9541
    31
*}
nipkow@8745
    32
(*<*)
nipkow@8745
    33
end
nipkow@8745
    34
(*>*)