10561
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Option{\isadigit{2}}}%
|
17056
|
4 |
%
|
|
5 |
\isadelimtheory
|
|
6 |
%
|
|
7 |
\endisadelimtheory
|
|
8 |
%
|
|
9 |
\isatagtheory
|
|
10 |
%
|
|
11 |
\endisatagtheory
|
|
12 |
{\isafoldtheory}%
|
|
13 |
%
|
|
14 |
\isadelimtheory
|
|
15 |
%
|
|
16 |
\endisadelimtheory
|
10561
|
17 |
%
|
|
18 |
\begin{isamarkuptext}%
|
11428
|
19 |
\indexbold{*option (type)}\indexbold{*None (constant)}%
|
|
20 |
\indexbold{*Some (constant)}
|
10561
|
21 |
Our final datatype is very simple but still eminently useful:%
|
|
22 |
\end{isamarkuptext}%
|
17175
|
23 |
\isamarkuptrue%
|
|
24 |
\isacommand{datatype}\isamarkupfalse%
|
|
25 |
\ {\isacharprime}a\ option\ {\isacharequal}\ None\ {\isacharbar}\ Some\ {\isacharprime}a%
|
10561
|
26 |
\begin{isamarkuptext}%
|
|
27 |
\noindent
|
11310
|
28 |
Frequently one needs to add a distinguished element to some existing type.
|
10561
|
29 |
For example, type \isa{t\ option} can model the result of a computation that
|
|
30 |
may either terminate with an error (represented by \isa{None}) or return
|
|
31 |
some value \isa{v} (represented by \isa{Some\ v}).
|
|
32 |
Similarly, \isa{nat} extended with $\infty$ can be modeled by type
|
|
33 |
\isa{nat\ option}. In both cases one could define a new datatype with
|
|
34 |
customized constructors like \isa{Error} and \isa{Infinity},
|
|
35 |
but it is often simpler to use \isa{option}. For an application see
|
|
36 |
\S\ref{sec:Trie}.%
|
|
37 |
\end{isamarkuptext}%
|
17175
|
38 |
\isamarkuptrue%
|
17056
|
39 |
%
|
|
40 |
\isadelimtheory
|
|
41 |
%
|
|
42 |
\endisadelimtheory
|
|
43 |
%
|
|
44 |
\isatagtheory
|
|
45 |
%
|
|
46 |
\endisatagtheory
|
|
47 |
{\isafoldtheory}%
|
|
48 |
%
|
|
49 |
\isadelimtheory
|
|
50 |
%
|
|
51 |
\endisadelimtheory
|
10561
|
52 |
\end{isabellebody}%
|
|
53 |
%%% Local Variables:
|
|
54 |
%%% mode: latex
|
|
55 |
%%% TeX-master: "root"
|
|
56 |
%%% End:
|