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