doc-src/TutorialI/Misc/document/pairs.tex
author nipkow
Sun, 06 Aug 2000 15:26:53 +0200
changeset 9541 d17c0b34d5c8
parent 9145 9f7b8de5bfaf
child 9644 6b0b6b471855
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     1
\begin{isabelle}%
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     2
%
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     3
\begin{isamarkuptext}%
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     4
HOL also has pairs: \isa{($a@1$,$a@2$)} is of type \isa{$\tau@1$ *
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     5
  $\tau@2$} provided each $a@i$ is of type $\tau@i$. The components of a pair
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     6
are extracted by \isa{fst} and \isa{snd}: \isa{fst($x$,$y$) = $x$} and
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     7
\isa{snd($x$,$y$) = $y$}. Tuples are simulated by pairs nested to the right:
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     8
\isa{($a@1$,$a@2$,$a@3$)} stands for \isa{($a@1$,($a@2$,$a@3$))} and
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
     9
\isa{$\tau@1$ * $\tau@2$ * $\tau@3$} for \isa{$\tau@1$ * ($\tau@2$ *
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    10
  $\tau@3$)}. Therefore we have \isa{fst(snd($a@1$,$a@2$,$a@3$)) = $a@2$}.
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    11
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    12
It is possible to use (nested) tuples as patterns in abstractions, for
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    13
example \isa{\isasymlambda(x,y,z).x+y+z} and
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    14
\isa{\isasymlambda((x,y),z).x+y+z}.
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    15
In addition to explicit $\lambda$-abstractions, tuple patterns can be used in
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    16
most variable binding constructs. Typical examples are
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    17
\begin{quote}
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    18
\isa{let\ (x,\ y)\ =\ f\ z\ in\ (y,\ x)}\\
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    19
\isa{case\ xs\ of\ []\ {\isasymRightarrow}\ 0\ |\ (x,\ y)\ \#\ zs\ {\isasymRightarrow}\ x\ +\ y}
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    20
\end{quote}
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    21
Further important examples are quantifiers and sets (see~\S\ref{quant-pats}).%
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9145
diff changeset
    22
\end{isamarkuptext}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    23
\end{isabelle}%
9145
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    24
%%% Local Variables:
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    25
%%% mode: latex
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    26
%%% TeX-master: "root"
9f7b8de5bfaf updated;
wenzelm
parents: 8749
diff changeset
    27
%%% End: