src/HOL/Option.thy
author wenzelm
Fri, 12 Apr 2013 17:21:51 +0200
changeset 51703 f2e92fc0c8aa
parent 51096 60e4b75fefe1
child 52435 6646bb548c6b
permissions -rw-r--r--
modifiers for classical wrappers operate on Proof.context instead of claset;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Option.thy
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     2
    Author:     Folklore
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     3
*)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     4
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     5
header {* Datatype option *}
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     6
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     7
theory Option
35719
99b6152aedf5 split off theory Big_Operators from theory Finite_Set
haftmann
parents: 34886
diff changeset
     8
imports Datatype
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
     9
begin
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    10
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    11
datatype 'a option = None | Some 'a
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    12
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    13
lemma not_None_eq [iff]: "(x ~= None) = (EX y. x = Some y)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    14
  by (induct x) auto
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    15
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    16
lemma not_Some_eq [iff]: "(ALL y. x ~= Some y) = (x = None)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    17
  by (induct x) auto
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    18
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    19
text{*Although it may appear that both of these equalities are helpful
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    20
only when applied to assumptions, in practice it seems better to give
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    21
them the uniform iff attribute. *}
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    22
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30327
diff changeset
    23
lemma inj_Some [simp]: "inj_on Some A"
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30327
diff changeset
    24
by (rule inj_onI) simp
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30327
diff changeset
    25
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    26
lemma option_caseE:
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    27
  assumes c: "(case x of None => P | Some y => Q y)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    28
  obtains
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    29
    (None) "x = None" and P
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    30
  | (Some) y where "x = Some y" and "Q y"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    31
  using c by (cases x) simp_all
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    32
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30327
diff changeset
    33
lemma UNIV_option_conv: "UNIV = insert None (range Some)"
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30327
diff changeset
    34
by(auto intro: classical)
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30327
diff changeset
    35
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    36
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    37
subsubsection {* Operations *}
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    38
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    39
primrec the :: "'a option => 'a" where
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    40
"the (Some x) = x"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    41
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    42
primrec set :: "'a option => 'a set" where
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    43
"set None = {}" |
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    44
"set (Some x) = {x}"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    45
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    46
lemma ospec [dest]: "(ALL x:set A. P x) ==> A = Some x ==> P x"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    47
  by simp
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    48
51703
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 51096
diff changeset
    49
setup {* map_theory_claset (fn ctxt => ctxt addSD2 ("ospec", @{thm ospec})) *}
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    50
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    51
lemma elem_set [iff]: "(x : set xo) = (xo = Some x)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    52
  by (cases xo) auto
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    53
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    54
lemma set_empty_eq [simp]: "(set xo = {}) = (xo = None)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    55
  by (cases xo) auto
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    56
31154
f919b8e67413 preprocessing must consider eq
haftmann
parents: 31080
diff changeset
    57
definition map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a option \<Rightarrow> 'b option" where
f919b8e67413 preprocessing must consider eq
haftmann
parents: 31080
diff changeset
    58
  "map = (%f y. case y of None => None | Some x => Some (f x))"
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    59
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    60
lemma option_map_None [simp, code]: "map f None = None"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    61
  by (simp add: map_def)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    62
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    63
lemma option_map_Some [simp, code]: "map f (Some x) = Some (f x)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    64
  by (simp add: map_def)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    65
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    66
lemma option_map_is_None [iff]:
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    67
    "(map f opt = None) = (opt = None)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    68
  by (simp add: map_def split add: option.split)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    69
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    70
lemma option_map_eq_Some [iff]:
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    71
    "(map f xo = Some y) = (EX z. xo = Some z & f z = y)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    72
  by (simp add: map_def split add: option.split)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    73
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    74
lemma option_map_comp:
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    75
    "map f (map g opt) = map (f o g) opt"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    76
  by (simp add: map_def split add: option.split)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    77
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    78
lemma option_map_o_sum_case [simp]:
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    79
    "map f o sum_case g h = sum_case (map f o g) (map f o h)"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    80
  by (rule ext) (simp split: sum.split)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
    81
46526
c4cf9d03c352 added congruence rules for Option.{map|bind}
krauss
parents: 41505
diff changeset
    82
lemma map_cong: "x = y \<Longrightarrow> (\<And>a. y = Some a \<Longrightarrow> f a = g a) \<Longrightarrow> map f x = map g y"
c4cf9d03c352 added congruence rules for Option.{map|bind}
krauss
parents: 41505
diff changeset
    83
by (cases x) auto
c4cf9d03c352 added congruence rules for Option.{map|bind}
krauss
parents: 41505
diff changeset
    84
41505
6d19301074cf "enriched_type" replaces less specific "type_lifting"
haftmann
parents: 41372
diff changeset
    85
enriched_type map: Option.map proof -
41372
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    86
  fix f g
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    87
  show "Option.map f \<circ> Option.map g = Option.map (f \<circ> g)"
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    88
  proof
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    89
    fix x
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    90
    show "(Option.map f \<circ> Option.map g) x= Option.map (f \<circ> g) x"
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    91
      by (cases x) simp_all
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    92
  qed
40609
efb0d7878538 mapper for option type
haftmann
parents: 39272
diff changeset
    93
next
41372
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    94
  show "Option.map id = id"
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    95
  proof
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    96
    fix x
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    97
    show "Option.map id x = id x"
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    98
      by (cases x) simp_all
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
    99
  qed
40609
efb0d7878538 mapper for option type
haftmann
parents: 39272
diff changeset
   100
qed
efb0d7878538 mapper for option type
haftmann
parents: 39272
diff changeset
   101
51096
60e4b75fefe1 combinator List.those;
haftmann
parents: 49189
diff changeset
   102
lemma option_case_map [simp]:
60e4b75fefe1 combinator List.those;
haftmann
parents: 49189
diff changeset
   103
  "option_case g h (Option.map f x) = option_case g (h \<circ> f) x"
60e4b75fefe1 combinator List.those;
haftmann
parents: 49189
diff changeset
   104
  by (cases x) simp_all
60e4b75fefe1 combinator List.those;
haftmann
parents: 49189
diff changeset
   105
39149
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   106
primrec bind :: "'a option \<Rightarrow> ('a \<Rightarrow> 'b option) \<Rightarrow> 'b option" where
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   107
bind_lzero: "bind None f = None" |
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   108
bind_lunit: "bind (Some x) f = f x"
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   109
39149
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   110
lemma bind_runit[simp]: "bind x Some = x"
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   111
by (cases x) auto
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   112
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   113
lemma bind_assoc[simp]: "bind (bind x f) g = bind x (\<lambda>y. bind (f y) g)"
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   114
by (cases x) auto
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   115
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   116
lemma bind_rzero[simp]: "bind x (\<lambda>x. None) = None"
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   117
by (cases x) auto
aabd6d4a5c3a added Option.bind
krauss
parents: 38857
diff changeset
   118
46526
c4cf9d03c352 added congruence rules for Option.{map|bind}
krauss
parents: 41505
diff changeset
   119
lemma bind_cong: "x = y \<Longrightarrow> (\<And>a. y = Some a \<Longrightarrow> f a = g a) \<Longrightarrow> bind x f = bind y g"
c4cf9d03c352 added congruence rules for Option.{map|bind}
krauss
parents: 41505
diff changeset
   120
by (cases x) auto
c4cf9d03c352 added congruence rules for Option.{map|bind}
krauss
parents: 41505
diff changeset
   121
49189
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   122
definition these :: "'a option set \<Rightarrow> 'a set"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   123
where
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   124
  "these A = the ` {x \<in> A. x \<noteq> None}"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   125
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   126
lemma these_empty [simp]:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   127
  "these {} = {}"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   128
  by (simp add: these_def)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   129
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   130
lemma these_insert_None [simp]:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   131
  "these (insert None A) = these A"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   132
  by (auto simp add: these_def)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   133
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   134
lemma these_insert_Some [simp]:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   135
  "these (insert (Some x) A) = insert x (these A)"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   136
proof -
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   137
  have "{y \<in> insert (Some x) A. y \<noteq> None} = insert (Some x) {y \<in> A. y \<noteq> None}"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   138
    by auto
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   139
  then show ?thesis by (simp add: these_def)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   140
qed
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   141
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   142
lemma in_these_eq:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   143
  "x \<in> these A \<longleftrightarrow> Some x \<in> A"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   144
proof
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   145
  assume "Some x \<in> A"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   146
  then obtain B where "A = insert (Some x) B" by auto
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   147
  then show "x \<in> these A" by (auto simp add: these_def intro!: image_eqI)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   148
next
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   149
  assume "x \<in> these A"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   150
  then show "Some x \<in> A" by (auto simp add: these_def)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   151
qed
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   152
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   153
lemma these_image_Some_eq [simp]:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   154
  "these (Some ` A) = A"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   155
  by (auto simp add: these_def intro!: image_eqI)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   156
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   157
lemma Some_image_these_eq:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   158
  "Some ` these A = {x\<in>A. x \<noteq> None}"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   159
  by (auto simp add: these_def image_image intro!: image_eqI)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   160
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   161
lemma these_empty_eq:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   162
  "these B = {} \<longleftrightarrow> B = {} \<or> B = {None}"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   163
  by (auto simp add: these_def)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   164
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   165
lemma these_not_empty_eq:
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   166
  "these B \<noteq> {} \<longleftrightarrow> B \<noteq> {} \<and> B \<noteq> {None}"
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   167
  by (auto simp add: these_empty_eq)
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   168
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   169
hide_const (open) set map bind these
46526
c4cf9d03c352 added congruence rules for Option.{map|bind}
krauss
parents: 41505
diff changeset
   170
hide_fact (open) map_cong bind_cong
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   171
49189
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   172
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   173
subsubsection {* Code generator setup *}
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   174
31154
f919b8e67413 preprocessing must consider eq
haftmann
parents: 31080
diff changeset
   175
definition is_none :: "'a option \<Rightarrow> bool" where
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31154
diff changeset
   176
  [code_post]: "is_none x \<longleftrightarrow> x = None"
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   177
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   178
lemma is_none_code [code]:
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   179
  shows "is_none None \<longleftrightarrow> True"
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   180
    and "is_none (Some x) \<longleftrightarrow> False"
31154
f919b8e67413 preprocessing must consider eq
haftmann
parents: 31080
diff changeset
   181
  unfolding is_none_def by simp_all
f919b8e67413 preprocessing must consider eq
haftmann
parents: 31080
diff changeset
   182
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
   183
lemma [code_unfold]:
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37880
diff changeset
   184
  "HOL.equal x None \<longleftrightarrow> is_none x"
39150
c4ff5fd8db99 removed duplicate lemma
krauss
parents: 39149
diff changeset
   185
  by (simp add: equal is_none_def)
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   186
36176
3fe7e97ccca8 replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents: 35719
diff changeset
   187
hide_const (open) is_none
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   188
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   189
code_type option
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   190
  (SML "_ option")
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   191
  (OCaml "_ option")
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   192
  (Haskell "Maybe _")
34886
873c31d9f10d some syntax setup for Scala
haftmann
parents: 32069
diff changeset
   193
  (Scala "!Option[(_)]")
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   194
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   195
code_const None and Some
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   196
  (SML "NONE" and "SOME")
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   197
  (OCaml "None" and "Some _")
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   198
  (Haskell "Nothing" and "Just")
37880
3b9ca8d2c5fb Scala: subtle difference in printing strings vs. complex mixfix syntax
haftmann
parents: 36176
diff changeset
   199
  (Scala "!None" and "Some")
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   200
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37880
diff changeset
   201
code_instance option :: equal
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   202
  (Haskell -)
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   203
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37880
diff changeset
   204
code_const "HOL.equal \<Colon> 'a option \<Rightarrow> 'a option \<Rightarrow> bool"
39272
0b61951d2682 Haskell == is infix, not infixl
haftmann
parents: 39159
diff changeset
   205
  (Haskell infix 4 "==")
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   206
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   207
code_reserved SML
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   208
  option NONE SOME
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   209
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   210
code_reserved OCaml
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   211
  option None Some
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   212
34886
873c31d9f10d some syntax setup for Scala
haftmann
parents: 32069
diff changeset
   213
code_reserved Scala
873c31d9f10d some syntax setup for Scala
haftmann
parents: 32069
diff changeset
   214
  Option None Some
873c31d9f10d some syntax setup for Scala
haftmann
parents: 32069
diff changeset
   215
30246
8253519dfc90 Option.thy
nipkow
parents:
diff changeset
   216
end
49189
3f85cd15a0cc combinator Option.these
haftmann
parents: 46526
diff changeset
   217