| author | wenzelm | 
| Sun, 01 Oct 2017 20:50:26 +0200 | |
| changeset 66744 | fec1504e5f03 | 
| parent 66364 | fa3247e6ee4b | 
| child 67091 | 1393c2340eec | 
| permissions | -rw-r--r-- | 
| 30246 | 1 | (* Title: HOL/Option.thy | 
| 2 | Author: Folklore | |
| 3 | *) | |
| 4 | ||
| 60758 | 5 | section \<open>Datatype option\<close> | 
| 30246 | 6 | |
| 7 | theory Option | |
| 66364 | 8 | imports Lifting | 
| 30246 | 9 | begin | 
| 10 | ||
| 58310 | 11 | datatype 'a option = | 
| 57091 | 12 | None | 
| 55406 | 13 | | Some (the: 'a) | 
| 57123 
b5324647e0f1
tuned whitespace, to make datatype definitions slightly less intimidating
 blanchet parents: 
57091diff
changeset | 14 | |
| 55531 
601ca8efa000
renamed 'datatype_new_compat' to 'datatype_compat'
 blanchet parents: 
55518diff
changeset | 15 | datatype_compat option | 
| 55404 
5cb95b79a51f
transformed 'option' and 'list' into new-style datatypes (but register them as old-style as well)
 blanchet parents: 
55129diff
changeset | 16 | |
| 55406 | 17 | lemma [case_names None Some, cases type: option]: | 
| 61799 | 18 | \<comment> \<open>for backward compatibility -- names of variables differ\<close> | 
| 55417 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
 blanchet parents: 
55414diff
changeset | 19 | "(y = None \<Longrightarrow> P) \<Longrightarrow> (\<And>a. y = Some a \<Longrightarrow> P) \<Longrightarrow> P" | 
| 61066 | 20 | by (rule option.exhaust) | 
| 55406 | 21 | |
| 22 | lemma [case_names None Some, induct type: option]: | |
| 61799 | 23 | \<comment> \<open>for backward compatibility -- names of variables differ\<close> | 
| 55406 | 24 | "P None \<Longrightarrow> (\<And>option. P (Some option)) \<Longrightarrow> P option" | 
| 61066 | 25 | by (rule option.induct) | 
| 55406 | 26 | |
| 60758 | 27 | text \<open>Compatibility:\<close> | 
| 28 | setup \<open>Sign.mandatory_path "option"\<close> | |
| 55404 
5cb95b79a51f
transformed 'option' and 'list' into new-style datatypes (but register them as old-style as well)
 blanchet parents: 
55129diff
changeset | 29 | lemmas inducts = option.induct | 
| 
5cb95b79a51f
transformed 'option' and 'list' into new-style datatypes (but register them as old-style as well)
 blanchet parents: 
55129diff
changeset | 30 | lemmas cases = option.case | 
| 60758 | 31 | setup \<open>Sign.parent_path\<close> | 
| 30246 | 32 | |
| 61066 | 33 | lemma not_None_eq [iff]: "x \<noteq> None \<longleftrightarrow> (\<exists>y. x = Some y)" | 
| 30246 | 34 | by (induct x) auto | 
| 35 | ||
| 61066 | 36 | lemma not_Some_eq [iff]: "(\<forall>y. x \<noteq> Some y) \<longleftrightarrow> x = None" | 
| 30246 | 37 | by (induct x) auto | 
| 38 | ||
| 61066 | 39 | text \<open>Although it may appear that both of these equalities are helpful | 
| 30246 | 40 | only when applied to assumptions, in practice it seems better to give | 
| 60758 | 41 | them the uniform iff attribute.\<close> | 
| 30246 | 42 | |
| 31080 | 43 | lemma inj_Some [simp]: "inj_on Some A" | 
| 61066 | 44 | by (rule inj_onI) simp | 
| 31080 | 45 | |
| 55404 
5cb95b79a51f
transformed 'option' and 'list' into new-style datatypes (but register them as old-style as well)
 blanchet parents: 
55129diff
changeset | 46 | lemma case_optionE: | 
| 61066 | 47 | assumes c: "(case x of None \<Rightarrow> P | Some y \<Rightarrow> Q y)" | 
| 30246 | 48 | obtains | 
| 49 | (None) "x = None" and P | |
| 50 | | (Some) y where "x = Some y" and "Q y" | |
| 51 | using c by (cases x) simp_all | |
| 52 | ||
| 53010 | 53 | lemma split_option_all: "(\<forall>x. P x) \<longleftrightarrow> P None \<and> (\<forall>x. P (Some x))" | 
| 61066 | 54 | by (auto intro: option.induct) | 
| 53010 | 55 | |
| 56 | lemma split_option_ex: "(\<exists>x. P x) \<longleftrightarrow> P None \<or> (\<exists>x. P (Some x))" | |
| 61066 | 57 | using split_option_all[of "\<lambda>x. \<not> P x"] by blast | 
| 53010 | 58 | |
| 31080 | 59 | lemma UNIV_option_conv: "UNIV = insert None (range Some)" | 
| 61066 | 60 | by (auto intro: classical) | 
| 31080 | 61 | |
| 59522 | 62 | lemma rel_option_None1 [simp]: "rel_option P None x \<longleftrightarrow> x = None" | 
| 61066 | 63 | by (cases x) simp_all | 
| 59522 | 64 | |
| 65 | lemma rel_option_None2 [simp]: "rel_option P x None \<longleftrightarrow> x = None" | |
| 61066 | 66 | by (cases x) simp_all | 
| 59522 | 67 | |
| 61630 | 68 | lemma option_rel_Some1: "rel_option A (Some x) y \<longleftrightarrow> (\<exists>y'. y = Some y' \<and> A x y')" (* Option *) | 
| 69 | by(cases y) simp_all | |
| 70 | ||
| 71 | lemma option_rel_Some2: "rel_option A x (Some y) \<longleftrightarrow> (\<exists>x'. x = Some x' \<and> A x' y)" (* Option *) | |
| 72 | by(cases x) simp_all | |
| 73 | ||
| 61066 | 74 | lemma rel_option_inf: "inf (rel_option A) (rel_option B) = rel_option (inf A B)" | 
| 75 | (is "?lhs = ?rhs") | |
| 76 | proof (rule antisym) | |
| 77 | show "?lhs \<le> ?rhs" by (auto elim: option.rel_cases) | |
| 78 | show "?rhs \<le> ?lhs" by (auto elim: option.rel_mono_strong) | |
| 79 | qed | |
| 59522 | 80 | |
| 81 | lemma rel_option_reflI: | |
| 82 | "(\<And>x. x \<in> set_option y \<Longrightarrow> P x x) \<Longrightarrow> rel_option P y y" | |
| 61066 | 83 | by (cases y) auto | 
| 59522 | 84 | |
| 59523 | 85 | |
| 60758 | 86 | subsubsection \<open>Operations\<close> | 
| 30246 | 87 | |
| 61066 | 88 | lemma ospec [dest]: "(\<forall>x\<in>set_option A. P x) \<Longrightarrow> A = Some x \<Longrightarrow> P x" | 
| 30246 | 89 | by simp | 
| 90 | ||
| 60758 | 91 | setup \<open>map_theory_claset (fn ctxt => ctxt addSD2 ("ospec", @{thm ospec}))\<close>
 | 
| 30246 | 92 | |
| 61066 | 93 | lemma elem_set [iff]: "(x \<in> set_option xo) = (xo = Some x)" | 
| 30246 | 94 | by (cases xo) auto | 
| 95 | ||
| 55518 
1ddb2edf5ceb
folded 'Option.set' into BNF-generated 'set_option'
 blanchet parents: 
55467diff
changeset | 96 | lemma set_empty_eq [simp]: "(set_option xo = {}) = (xo = None)"
 | 
| 30246 | 97 | by (cases xo) auto | 
| 98 | ||
| 61066 | 99 | lemma map_option_case: "map_option f y = (case y of None \<Rightarrow> None | Some x \<Rightarrow> Some (f x))" | 
| 55466 | 100 | by (auto split: option.split) | 
| 30246 | 101 | |
| 61066 | 102 | lemma map_option_is_None [iff]: "(map_option f opt = None) = (opt = None)" | 
| 63648 | 103 | by (simp add: map_option_case split: option.split) | 
| 30246 | 104 | |
| 61630 | 105 | lemma None_eq_map_option_iff [iff]: "None = map_option f x \<longleftrightarrow> x = None" | 
| 106 | by(cases x) simp_all | |
| 107 | ||
| 61066 | 108 | lemma map_option_eq_Some [iff]: "(map_option f xo = Some y) = (\<exists>z. xo = Some z \<and> f z = y)" | 
| 63648 | 109 | by (simp add: map_option_case split: option.split) | 
| 30246 | 110 | |
| 55466 | 111 | lemma map_option_o_case_sum [simp]: | 
| 112 | "map_option f o case_sum g h = case_sum (map_option f o g) (map_option f o h)" | |
| 113 | by (rule o_case_sum) | |
| 30246 | 114 | |
| 55466 | 115 | lemma map_option_cong: "x = y \<Longrightarrow> (\<And>a. y = Some a \<Longrightarrow> f a = g a) \<Longrightarrow> map_option f x = map_option g y" | 
| 61066 | 116 | by (cases x) auto | 
| 46526 | 117 | |
| 61630 | 118 | lemma map_option_idI: "(\<And>y. y \<in> set_option x \<Longrightarrow> f y = y) \<Longrightarrow> map_option f x = x" | 
| 119 | by(cases x)(simp_all) | |
| 120 | ||
| 59521 | 121 | functor map_option: map_option | 
| 61066 | 122 | by (simp_all add: option.map_comp fun_eq_iff option.map_id) | 
| 40609 | 123 | |
| 61066 | 124 | lemma case_map_option [simp]: "case_option g h (map_option f x) = case_option g (h \<circ> f) x" | 
| 51096 | 125 | by (cases x) simp_all | 
| 126 | ||
| 61630 | 127 | lemma None_notin_image_Some [simp]: "None \<notin> Some ` A" | 
| 128 | by auto | |
| 129 | ||
| 130 | lemma notin_range_Some: "x \<notin> range Some \<longleftrightarrow> x = None" | |
| 131 | by(cases x) auto | |
| 132 | ||
| 58916 | 133 | lemma rel_option_iff: | 
| 134 | "rel_option R x y = (case (x, y) of (None, None) \<Rightarrow> True | |
| 135 | | (Some x, Some y) \<Rightarrow> R x y | |
| 136 | | _ \<Rightarrow> False)" | |
| 61066 | 137 | by (auto split: prod.split option.split) | 
| 58916 | 138 | |
| 63194 | 139 | |
| 140 | definition combine_options :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'a option \<Rightarrow> 'a option \<Rightarrow> 'a option"
 | |
| 141 | where "combine_options f x y = | |
| 142 | (case x of None \<Rightarrow> y | Some x \<Rightarrow> (case y of None \<Rightarrow> Some x | Some y \<Rightarrow> Some (f x y)))" | |
| 143 | ||
| 144 | lemma combine_options_simps [simp]: | |
| 145 | "combine_options f None y = y" | |
| 146 | "combine_options f x None = x" | |
| 147 | "combine_options f (Some a) (Some b) = Some (f a b)" | |
| 148 | by (simp_all add: combine_options_def split: option.splits) | |
| 149 | ||
| 150 | lemma combine_options_cases [case_names None1 None2 Some]: | |
| 151 | "(x = None \<Longrightarrow> P x y) \<Longrightarrow> (y = None \<Longrightarrow> P x y) \<Longrightarrow> | |
| 152 | (\<And>a b. x = Some a \<Longrightarrow> y = Some b \<Longrightarrow> P x y) \<Longrightarrow> P x y" | |
| 153 | by (cases x; cases y) simp_all | |
| 154 | ||
| 155 | lemma combine_options_commute: | |
| 156 | "(\<And>x y. f x y = f y x) \<Longrightarrow> combine_options f x y = combine_options f y x" | |
| 157 | using combine_options_cases[of x ] | |
| 158 | by (induction x y rule: combine_options_cases) simp_all | |
| 159 | ||
| 160 | lemma combine_options_assoc: | |
| 161 | "(\<And>x y z. f (f x y) z = f x (f y z)) \<Longrightarrow> | |
| 162 | combine_options f (combine_options f x y) z = | |
| 163 | combine_options f x (combine_options f y z)" | |
| 164 | by (auto simp: combine_options_def split: option.splits) | |
| 165 | ||
| 166 | lemma combine_options_left_commute: | |
| 167 | "(\<And>x y. f x y = f y x) \<Longrightarrow> (\<And>x y z. f (f x y) z = f x (f y z)) \<Longrightarrow> | |
| 168 | combine_options f y (combine_options f x z) = | |
| 169 | combine_options f x (combine_options f y z)" | |
| 170 | by (auto simp: combine_options_def split: option.splits) | |
| 171 | ||
| 172 | lemmas combine_options_ac = | |
| 173 | combine_options_commute combine_options_assoc combine_options_left_commute | |
| 174 | ||
| 175 | ||
| 61068 | 176 | context | 
| 177 | begin | |
| 178 | ||
| 179 | qualified definition is_none :: "'a option \<Rightarrow> bool" | |
| 61066 | 180 | where [code_post]: "is_none x \<longleftrightarrow> x = None" | 
| 59522 | 181 | |
| 182 | lemma is_none_simps [simp]: | |
| 183 | "is_none None" | |
| 184 | "\<not> is_none (Some x)" | |
| 61066 | 185 | by (simp_all add: is_none_def) | 
| 59522 | 186 | |
| 187 | lemma is_none_code [code]: | |
| 188 | "is_none None = True" | |
| 189 | "is_none (Some x) = False" | |
| 61066 | 190 | by simp_all | 
| 59522 | 191 | |
| 192 | lemma rel_option_unfold: | |
| 193 | "rel_option R x y \<longleftrightarrow> | |
| 194 | (is_none x \<longleftrightarrow> is_none y) \<and> (\<not> is_none x \<longrightarrow> \<not> is_none y \<longrightarrow> R (the x) (the y))" | |
| 61066 | 195 | by (simp add: rel_option_iff split: option.split) | 
| 59522 | 196 | |
| 197 | lemma rel_optionI: | |
| 198 | "\<lbrakk> is_none x \<longleftrightarrow> is_none y; \<lbrakk> \<not> is_none x; \<not> is_none y \<rbrakk> \<Longrightarrow> P (the x) (the y) \<rbrakk> | |
| 199 | \<Longrightarrow> rel_option P x y" | |
| 61066 | 200 | by (simp add: rel_option_unfold) | 
| 59522 | 201 | |
| 202 | lemma is_none_map_option [simp]: "is_none (map_option f x) \<longleftrightarrow> is_none x" | |
| 61066 | 203 | by (simp add: is_none_def) | 
| 59522 | 204 | |
| 205 | lemma the_map_option: "\<not> is_none x \<Longrightarrow> the (map_option f x) = f (the x)" | |
| 61066 | 206 | by (auto simp add: is_none_def) | 
| 59522 | 207 | |
| 208 | ||
| 61068 | 209 | qualified primrec bind :: "'a option \<Rightarrow> ('a \<Rightarrow> 'b option) \<Rightarrow> 'b option"
 | 
| 61066 | 210 | where | 
| 211 | bind_lzero: "bind None f = None" | |
| 212 | | bind_lunit: "bind (Some x) f = f x" | |
| 30246 | 213 | |
| 59522 | 214 | lemma is_none_bind: "is_none (bind f g) \<longleftrightarrow> is_none f \<or> is_none (g (the f))" | 
| 61066 | 215 | by (cases f) simp_all | 
| 59522 | 216 | |
| 39149 | 217 | lemma bind_runit[simp]: "bind x Some = x" | 
| 61066 | 218 | by (cases x) auto | 
| 39149 | 219 | |
| 220 | lemma bind_assoc[simp]: "bind (bind x f) g = bind x (\<lambda>y. bind (f y) g)" | |
| 61066 | 221 | by (cases x) auto | 
| 39149 | 222 | |
| 223 | lemma bind_rzero[simp]: "bind x (\<lambda>x. None) = None" | |
| 61066 | 224 | by (cases x) auto | 
| 39149 | 225 | |
| 61068 | 226 | qualified lemma bind_cong: "x = y \<Longrightarrow> (\<And>a. y = Some a \<Longrightarrow> f a = g a) \<Longrightarrow> bind x f = bind y g" | 
| 61066 | 227 | by (cases x) auto | 
| 46526 | 228 | |
| 61066 | 229 | lemma bind_split: "P (bind m f) \<longleftrightarrow> (m = None \<longrightarrow> P None) \<and> (\<forall>v. m = Some v \<longrightarrow> P (f v))" | 
| 230 | by (cases m) auto | |
| 58895 
de0a4a76d7aa
Added Option.bind_split{,_asm,s}
 lammich <lammich@in.tum.de> parents: 
58889diff
changeset | 231 | |
| 61066 | 232 | lemma bind_split_asm: "P (bind m f) \<longleftrightarrow> \<not> (m = None \<and> \<not> P None \<or> (\<exists>x. m = Some x \<and> \<not> P (f x)))" | 
| 58895 
de0a4a76d7aa
Added Option.bind_split{,_asm,s}
 lammich <lammich@in.tum.de> parents: 
58889diff
changeset | 233 | by (cases m) auto | 
| 
de0a4a76d7aa
Added Option.bind_split{,_asm,s}
 lammich <lammich@in.tum.de> parents: 
58889diff
changeset | 234 | |
| 
de0a4a76d7aa
Added Option.bind_split{,_asm,s}
 lammich <lammich@in.tum.de> parents: 
58889diff
changeset | 235 | lemmas bind_splits = bind_split bind_split_asm | 
| 
de0a4a76d7aa
Added Option.bind_split{,_asm,s}
 lammich <lammich@in.tum.de> parents: 
58889diff
changeset | 236 | |
| 59522 | 237 | lemma bind_eq_Some_conv: "bind f g = Some x \<longleftrightarrow> (\<exists>y. f = Some y \<and> g y = Some x)" | 
| 61066 | 238 | by (cases f) simp_all | 
| 59522 | 239 | |
| 61630 | 240 | lemma bind_eq_None_conv: "Option.bind a f = None \<longleftrightarrow> a = None \<or> f (the a) = None" | 
| 241 | by(cases a) simp_all | |
| 242 | ||
| 59522 | 243 | lemma map_option_bind: "map_option f (bind x g) = bind x (map_option f \<circ> g)" | 
| 61066 | 244 | by (cases x) simp_all | 
| 59522 | 245 | |
| 246 | lemma bind_option_cong: | |
| 247 | "\<lbrakk> x = y; \<And>z. z \<in> set_option y \<Longrightarrow> f z = g z \<rbrakk> \<Longrightarrow> bind x f = bind y g" | |
| 61066 | 248 | by (cases y) simp_all | 
| 59522 | 249 | |
| 250 | lemma bind_option_cong_simp: | |
| 251 | "\<lbrakk> x = y; \<And>z. z \<in> set_option y =simp=> f z = g z \<rbrakk> \<Longrightarrow> bind x f = bind y g" | |
| 61066 | 252 | unfolding simp_implies_def by (rule bind_option_cong) | 
| 59522 | 253 | |
| 61066 | 254 | lemma bind_option_cong_code: "x = y \<Longrightarrow> bind x f = bind y f" | 
| 255 | by simp | |
| 61068 | 256 | |
| 61630 | 257 | lemma bind_map_option: "bind (map_option f x) g = bind x (g \<circ> f)" | 
| 258 | by(cases x) simp_all | |
| 259 | ||
| 260 | lemma set_bind_option [simp]: "set_option (bind x f) = UNION (set_option x) (set_option \<circ> f)" | |
| 261 | by(cases x) auto | |
| 262 | ||
| 263 | lemma map_conv_bind_option: "map_option f x = Option.bind x (Some \<circ> f)" | |
| 264 | by(cases x) simp_all | |
| 265 | ||
| 61068 | 266 | end | 
| 267 | ||
| 59522 | 268 | setup \<open>Code_Simp.map_ss (Simplifier.add_cong @{thm bind_option_cong_code})\<close>
 | 
| 269 | ||
| 270 | ||
| 61068 | 271 | context | 
| 272 | begin | |
| 273 | ||
| 274 | qualified definition these :: "'a option set \<Rightarrow> 'a set" | |
| 61066 | 275 |   where "these A = the ` {x \<in> A. x \<noteq> None}"
 | 
| 49189 | 276 | |
| 61066 | 277 | lemma these_empty [simp]: "these {} = {}"
 | 
| 49189 | 278 | by (simp add: these_def) | 
| 279 | ||
| 61066 | 280 | lemma these_insert_None [simp]: "these (insert None A) = these A" | 
| 49189 | 281 | by (auto simp add: these_def) | 
| 282 | ||
| 61066 | 283 | lemma these_insert_Some [simp]: "these (insert (Some x) A) = insert x (these A)" | 
| 49189 | 284 | proof - | 
| 285 |   have "{y \<in> insert (Some x) A. y \<noteq> None} = insert (Some x) {y \<in> A. y \<noteq> None}"
 | |
| 286 | by auto | |
| 287 | then show ?thesis by (simp add: these_def) | |
| 288 | qed | |
| 289 | ||
| 61066 | 290 | lemma in_these_eq: "x \<in> these A \<longleftrightarrow> Some x \<in> A" | 
| 49189 | 291 | proof | 
| 292 | assume "Some x \<in> A" | |
| 293 | then obtain B where "A = insert (Some x) B" by auto | |
| 294 | then show "x \<in> these A" by (auto simp add: these_def intro!: image_eqI) | |
| 295 | next | |
| 296 | assume "x \<in> these A" | |
| 297 | then show "Some x \<in> A" by (auto simp add: these_def) | |
| 298 | qed | |
| 299 | ||
| 61066 | 300 | lemma these_image_Some_eq [simp]: "these (Some ` A) = A" | 
| 49189 | 301 | by (auto simp add: these_def intro!: image_eqI) | 
| 302 | ||
| 61066 | 303 | lemma Some_image_these_eq: "Some ` these A = {x\<in>A. x \<noteq> None}"
 | 
| 49189 | 304 | by (auto simp add: these_def image_image intro!: image_eqI) | 
| 305 | ||
| 61066 | 306 | lemma these_empty_eq: "these B = {} \<longleftrightarrow> B = {} \<or> B = {None}"
 | 
| 49189 | 307 | by (auto simp add: these_def) | 
| 308 | ||
| 61066 | 309 | lemma these_not_empty_eq: "these B \<noteq> {} \<longleftrightarrow> B \<noteq> {} \<and> B \<noteq> {None}"
 | 
| 49189 | 310 | by (auto simp add: these_empty_eq) | 
| 311 | ||
| 61068 | 312 | end | 
| 30246 | 313 | |
| 49189 | 314 | |
| 60758 | 315 | subsection \<open>Transfer rules for the Transfer package\<close> | 
| 58916 | 316 | |
| 63343 | 317 | context includes lifting_syntax | 
| 58916 | 318 | begin | 
| 61066 | 319 | |
| 58916 | 320 | lemma option_bind_transfer [transfer_rule]: | 
| 321 | "(rel_option A ===> (A ===> rel_option B) ===> rel_option B) | |
| 322 | Option.bind Option.bind" | |
| 323 | unfolding rel_fun_def split_option_all by simp | |
| 324 | ||
| 59523 | 325 | lemma pred_option_parametric [transfer_rule]: | 
| 326 | "((A ===> op =) ===> rel_option A ===> op =) pred_option pred_option" | |
| 61068 | 327 | by (rule rel_funI)+ (auto simp add: rel_option_unfold Option.is_none_def dest: rel_funD) | 
| 59523 | 328 | |
| 58916 | 329 | end | 
| 330 | ||
| 331 | ||
| 60758 | 332 | subsubsection \<open>Interaction with finite sets\<close> | 
| 55089 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 333 | |
| 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 334 | lemma finite_option_UNIV [simp]: | 
| 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 335 | "finite (UNIV :: 'a option set) = finite (UNIV :: 'a set)" | 
| 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 336 | by (auto simp add: UNIV_option_conv elim: finite_imageD intro: inj_Some) | 
| 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 337 | |
| 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 338 | instance option :: (finite) finite | 
| 61066 | 339 | by standard (simp add: UNIV_option_conv) | 
| 55089 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 340 | |
| 
181751ad852f
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
 blanchet parents: 
53940diff
changeset | 341 | |
| 60758 | 342 | subsubsection \<open>Code generator setup\<close> | 
| 30246 | 343 | |
| 59522 | 344 | lemma equal_None_code_unfold [code_unfold]: | 
| 61068 | 345 | "HOL.equal x None \<longleftrightarrow> Option.is_none x" | 
| 346 | "HOL.equal None = Option.is_none" | |
| 347 | by (auto simp add: equal Option.is_none_def) | |
| 30246 | 348 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 349 | code_printing | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 350 | type_constructor option \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 351 | (SML) "_ option" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 352 | and (OCaml) "_ option" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 353 | and (Haskell) "Maybe _" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 354 | and (Scala) "!Option[(_)]" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 355 | | constant None \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 356 | (SML) "NONE" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 357 | and (OCaml) "None" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 358 | and (Haskell) "Nothing" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 359 | and (Scala) "!None" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 360 | | constant Some \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 361 | (SML) "SOME" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 362 | and (OCaml) "Some _" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 363 | and (Haskell) "Just" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 364 | and (Scala) "Some" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 365 | | class_instance option :: equal \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 366 | (Haskell) - | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 367 | | constant "HOL.equal :: 'a option \<Rightarrow> 'a option \<Rightarrow> bool" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51703diff
changeset | 368 | (Haskell) infix 4 "==" | 
| 30246 | 369 | |
| 370 | code_reserved SML | |
| 371 | option NONE SOME | |
| 372 | ||
| 373 | code_reserved OCaml | |
| 374 | option None Some | |
| 375 | ||
| 34886 | 376 | code_reserved Scala | 
| 377 | Option None Some | |
| 378 | ||
| 30246 | 379 | end |