src/HOL/Datatype.thy
changeset 30235 58d147683393
parent 29609 a010aab5bed0
child 33633 9f7280e0c231
     1.1 --- a/src/HOL/Datatype.thy	Tue Mar 03 17:05:18 2009 +0100
     1.2 +++ b/src/HOL/Datatype.thy	Wed Mar 04 10:47:20 2009 +0100
     1.3 @@ -576,122 +576,4 @@
     1.4  
     1.5  hide (open) const Suml Sumr Projl Projr
     1.6  
     1.7 -
     1.8 -subsection {* The option datatype *}
     1.9 -
    1.10 -datatype 'a option = None | Some 'a
    1.11 -
    1.12 -lemma not_None_eq [iff]: "(x ~= None) = (EX y. x = Some y)"
    1.13 -  by (induct x) auto
    1.14 -
    1.15 -lemma not_Some_eq [iff]: "(ALL y. x ~= Some y) = (x = None)"
    1.16 -  by (induct x) auto
    1.17 -
    1.18 -text{*Although it may appear that both of these equalities are helpful
    1.19 -only when applied to assumptions, in practice it seems better to give
    1.20 -them the uniform iff attribute. *}
    1.21 -
    1.22 -lemma option_caseE:
    1.23 -  assumes c: "(case x of None => P | Some y => Q y)"
    1.24 -  obtains
    1.25 -    (None) "x = None" and P
    1.26 -  | (Some) y where "x = Some y" and "Q y"
    1.27 -  using c by (cases x) simp_all
    1.28 -
    1.29 -lemma insert_None_conv_UNIV: "insert None (range Some) = UNIV"
    1.30 -  by (rule set_ext, case_tac x) auto
    1.31 -
    1.32 -lemma inj_Some [simp]: "inj_on Some A"
    1.33 -  by (rule inj_onI) simp
    1.34 -
    1.35 -
    1.36 -subsubsection {* Operations *}
    1.37 -
    1.38 -consts
    1.39 -  the :: "'a option => 'a"
    1.40 -primrec
    1.41 -  "the (Some x) = x"
    1.42 -
    1.43 -consts
    1.44 -  o2s :: "'a option => 'a set"
    1.45 -primrec
    1.46 -  "o2s None = {}"
    1.47 -  "o2s (Some x) = {x}"
    1.48 -
    1.49 -lemma ospec [dest]: "(ALL x:o2s A. P x) ==> A = Some x ==> P x"
    1.50 -  by simp
    1.51 -
    1.52 -declaration {* fn _ =>
    1.53 -  Classical.map_cs (fn cs => cs addSD2 ("ospec", thm "ospec"))
    1.54 -*}
    1.55 -
    1.56 -lemma elem_o2s [iff]: "(x : o2s xo) = (xo = Some x)"
    1.57 -  by (cases xo) auto
    1.58 -
    1.59 -lemma o2s_empty_eq [simp]: "(o2s xo = {}) = (xo = None)"
    1.60 -  by (cases xo) auto
    1.61 -
    1.62 -definition
    1.63 -  option_map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a option \<Rightarrow> 'b option"
    1.64 -where
    1.65 -  [code del]: "option_map = (%f y. case y of None => None | Some x => Some (f x))"
    1.66 -
    1.67 -lemma option_map_None [simp, code]: "option_map f None = None"
    1.68 -  by (simp add: option_map_def)
    1.69 -
    1.70 -lemma option_map_Some [simp, code]: "option_map f (Some x) = Some (f x)"
    1.71 -  by (simp add: option_map_def)
    1.72 -
    1.73 -lemma option_map_is_None [iff]:
    1.74 -    "(option_map f opt = None) = (opt = None)"
    1.75 -  by (simp add: option_map_def split add: option.split)
    1.76 -
    1.77 -lemma option_map_eq_Some [iff]:
    1.78 -    "(option_map f xo = Some y) = (EX z. xo = Some z & f z = y)"
    1.79 -  by (simp add: option_map_def split add: option.split)
    1.80 -
    1.81 -lemma option_map_comp:
    1.82 -    "option_map f (option_map g opt) = option_map (f o g) opt"
    1.83 -  by (simp add: option_map_def split add: option.split)
    1.84 -
    1.85 -lemma option_map_o_sum_case [simp]:
    1.86 -    "option_map f o sum_case g h = sum_case (option_map f o g) (option_map f o h)"
    1.87 -  by (rule ext) (simp split: sum.split)
    1.88 -
    1.89 -
    1.90 -subsubsection {* Code generator setup *}
    1.91 -
    1.92 -definition
    1.93 -  is_none :: "'a option \<Rightarrow> bool" where
    1.94 -  is_none_none [code post, symmetric, code inline]: "is_none x \<longleftrightarrow> x = None"
    1.95 -
    1.96 -lemma is_none_code [code]:
    1.97 -  shows "is_none None \<longleftrightarrow> True"
    1.98 -    and "is_none (Some x) \<longleftrightarrow> False"
    1.99 -  unfolding is_none_none [symmetric] by simp_all
   1.100 -
   1.101 -hide (open) const is_none
   1.102 -
   1.103 -code_type option
   1.104 -  (SML "_ option")
   1.105 -  (OCaml "_ option")
   1.106 -  (Haskell "Maybe _")
   1.107 -
   1.108 -code_const None and Some
   1.109 -  (SML "NONE" and "SOME")
   1.110 -  (OCaml "None" and "Some _")
   1.111 -  (Haskell "Nothing" and "Just")
   1.112 -
   1.113 -code_instance option :: eq
   1.114 -  (Haskell -)
   1.115 -
   1.116 -code_const "eq_class.eq \<Colon> 'a\<Colon>eq option \<Rightarrow> 'a option \<Rightarrow> bool"
   1.117 -  (Haskell infixl 4 "==")
   1.118 -
   1.119 -code_reserved SML
   1.120 -  option NONE SOME
   1.121 -
   1.122 -code_reserved OCaml
   1.123 -  option None Some
   1.124 -
   1.125  end