doc-src/TutorialI/Misc/document/Option2.tex
author wenzelm
Mon, 29 Aug 2005 16:25:24 +0200
changeset 17187 45bee2f6e61f
parent 17181 5f42dd5e6570
child 40406 313a24b66a8d
permissions -rw-r--r--
updated;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
     1
%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
     2
\begin{isabellebody}%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
     3
\def\isabellecontext{Option{\isadigit{2}}}%
17056
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
     4
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
     5
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
     6
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
     7
\endisadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
     8
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
     9
\isatagtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    10
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    11
\endisatagtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    12
{\isafoldtheory}%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    13
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    14
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    15
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    16
\endisadelimtheory
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    17
%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    18
\begin{isamarkuptext}%
11428
332347b9b942 tidying the index
paulson
parents: 11310
diff changeset
    19
\indexbold{*option (type)}\indexbold{*None (constant)}%
332347b9b942 tidying the index
paulson
parents: 11310
diff changeset
    20
\indexbold{*Some (constant)}
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    21
Our final datatype is very simple but still eminently useful:%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    22
\end{isamarkuptext}%
17175
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    23
\isamarkuptrue%
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    24
\isacommand{datatype}\isamarkupfalse%
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    25
\ {\isacharprime}a\ option\ {\isacharequal}\ None\ {\isacharbar}\ Some\ {\isacharprime}a%
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    26
\begin{isamarkuptext}%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    27
\noindent
11310
51e70b7bc315 spelling check
paulson
parents: 10561
diff changeset
    28
Frequently one needs to add a distinguished element to some existing type.
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    29
For example, type \isa{t\ option} can model the result of a computation that
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    30
may either terminate with an error (represented by \isa{None}) or return
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    31
some value \isa{v} (represented by \isa{Some\ v}).
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    32
Similarly, \isa{nat} extended with $\infty$ can be modeled by type
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    33
\isa{nat\ option}. In both cases one could define a new datatype with
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    34
customized constructors like \isa{Error} and \isa{Infinity},
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    35
but it is often simpler to use \isa{option}. For an application see
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    36
\S\ref{sec:Trie}.%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    37
\end{isamarkuptext}%
17175
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    38
\isamarkuptrue%
17056
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    39
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    40
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    41
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    42
\endisadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    43
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    44
\isatagtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    45
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    46
\endisatagtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    47
{\isafoldtheory}%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    48
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    49
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    50
%
05fc32a23b8b updated;
wenzelm
parents: 13778
diff changeset
    51
\endisadelimtheory
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    52
\end{isabellebody}%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    53
%%% Local Variables:
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    54
%%% mode: latex
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    55
%%% TeX-master: "root"
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    56
%%% End: