doc-src/TutorialI/Misc/document/Option2.tex
author webertj
Mon, 12 Jan 2004 14:35:07 +0100
changeset 14351 cd3ef10d02be
parent 13778 61272514e3b5
child 17056 05fc32a23b8b
permissions -rw-r--r--
Fixed compatibility issues with SML/NJ: - replaced '(op *)' by 'op*' - replaced 'LargeInt' by 'Int'
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}}}%
11866
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
     4
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
     5
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
     6
\isamarkupfalse%
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
     7
%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
     8
\begin{isamarkuptext}%
11428
332347b9b942 tidying the index
paulson
parents: 11310
diff changeset
     9
\indexbold{*option (type)}\indexbold{*None (constant)}%
332347b9b942 tidying the index
paulson
parents: 11310
diff changeset
    10
\indexbold{*Some (constant)}
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    11
Our final datatype is very simple but still eminently useful:%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    12
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
    13
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
    14
\isacommand{datatype}\ {\isacharprime}a\ option\ {\isacharequal}\ None\ {\isacharbar}\ Some\ {\isacharprime}a\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
    15
%
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    16
\begin{isamarkuptext}%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    17
\noindent
11310
51e70b7bc315 spelling check
paulson
parents: 10561
diff changeset
    18
Frequently one needs to add a distinguished element to some existing type.
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    19
For example, type \isa{t\ option} can model the result of a computation that
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    20
may either terminate with an error (represented by \isa{None}) or return
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    21
some value \isa{v} (represented by \isa{Some\ v}).
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    22
Similarly, \isa{nat} extended with $\infty$ can be modeled by type
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    23
\isa{nat\ option}. In both cases one could define a new datatype with
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    24
customized constructors like \isa{Error} and \isa{Infinity},
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    25
but it is often simpler to use \isa{option}. For an application see
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    26
\S\ref{sec:Trie}.%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    27
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
    28
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11428
diff changeset
    29
\isamarkupfalse%
10561
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    30
\end{isabellebody}%
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    31
%%% Local Variables:
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    32
%%% mode: latex
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    33
%%% TeX-master: "root"
d960cc4a6afc *** empty log message ***
nipkow
parents:
diff changeset
    34
%%% End: