Theory Option2

(*<*)
theory Option2 imports Main begin
hide_const None Some
hide_type option
(*>*)

text‹\indexbold{*option (type)}\indexbold{*None (constant)}%
\indexbold{*Some (constant)}
Our final datatype is very simple but still eminently useful:
›

datatype 'a option = None | Some 'a

text‹\noindent
Frequently one needs to add a distinguished element to some existing type.
For example, type t option› can model the result of a computation that
may either terminate with an error (represented by constNone) or return
some value termv (represented by termSome v).
Similarly, typnat extended with $\infty$ can be modeled by type
typnat option. In both cases one could define a new datatype with
customized constructors like termError and termInfinity,
but it is often simpler to use option›. For an application see
\S\ref{sec:Trie}.
›
(*<*)
(*
definition infplus :: "nat option ⇒ nat option ⇒ nat option" where
"infplus x y ≡ case x of None ⇒ None
               | Some m ⇒ (case y of None ⇒ None | Some n ⇒ Some(m+n))"

*)
end
(*>*)