src/Doc/Tutorial/Misc/Option2.thy
changeset 69505 cc2d676d5395
parent 67406 23307fd33906
child 69597 ff784d5a5bfb
equal deleted inserted replaced
69504:bda7527ccf05 69505:cc2d676d5395
    11 
    11 
    12 datatype 'a option = None | Some 'a
    12 datatype 'a option = None | Some 'a
    13 
    13 
    14 text\<open>\noindent
    14 text\<open>\noindent
    15 Frequently one needs to add a distinguished element to some existing type.
    15 Frequently one needs to add a distinguished element to some existing type.
    16 For example, type @{text"t option"} can model the result of a computation that
    16 For example, type \<open>t option\<close> can model the result of a computation that
    17 may either terminate with an error (represented by @{const None}) or return
    17 may either terminate with an error (represented by @{const None}) or return
    18 some value @{term v} (represented by @{term"Some v"}).
    18 some value @{term v} (represented by @{term"Some v"}).
    19 Similarly, @{typ nat} extended with $\infty$ can be modeled by type
    19 Similarly, @{typ nat} extended with $\infty$ can be modeled by type
    20 @{typ"nat option"}. In both cases one could define a new datatype with
    20 @{typ"nat option"}. In both cases one could define a new datatype with
    21 customized constructors like @{term Error} and @{term Infinity},
    21 customized constructors like @{term Error} and @{term Infinity},
    22 but it is often simpler to use @{text option}. For an application see
    22 but it is often simpler to use \<open>option\<close>. For an application see
    23 \S\ref{sec:Trie}.
    23 \S\ref{sec:Trie}.
    24 \<close>
    24 \<close>
    25 (*<*)
    25 (*<*)
    26 (*
    26 (*
    27 definition infplus :: "nat option \<Rightarrow> nat option \<Rightarrow> nat option" where
    27 definition infplus :: "nat option \<Rightarrow> nat option \<Rightarrow> nat option" where