src/HOL/Inductive.thy
author haftmann
Tue Jun 23 16:27:12 2009 +0200 (2009-06-23)
changeset 31784 bd3486c57ba3
parent 31775 2b04504fcb69
child 31949 3f933687fae9
permissions -rw-r--r--
tuned interfaces of datatype module
wenzelm@7700
     1
(*  Title:      HOL/Inductive.thy
wenzelm@10402
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@11688
     3
*)
wenzelm@10727
     4
haftmann@24915
     5
header {* Knaster-Tarski Fixpoint Theorem and inductive definitions *}
lcp@1187
     6
nipkow@15131
     7
theory Inductive 
haftmann@24915
     8
imports Lattices Sum_Type
haftmann@16417
     9
uses
haftmann@31723
    10
  ("Tools/inductive.ML")
haftmann@24625
    11
  "Tools/dseq.ML"
berghofe@12437
    12
  ("Tools/inductive_codegen.ML")
haftmann@31775
    13
  ("Tools/Datatype/datatype_aux.ML")
haftmann@31775
    14
  ("Tools/Datatype/datatype_prop.ML")
haftmann@31775
    15
  ("Tools/Datatype/datatype_rep_proofs.ML")
haftmann@31775
    16
  ("Tools/Datatype/datatype_abs_proofs.ML")
haftmann@31775
    17
  ("Tools/Datatype/datatype_case.ML")
haftmann@31775
    18
  ("Tools/Datatype/datatype.ML")
haftmann@31723
    19
  ("Tools/old_primrec.ML")
haftmann@31723
    20
  ("Tools/primrec.ML")
haftmann@31775
    21
  ("Tools/Datatype/datatype_codegen.ML")
nipkow@15131
    22
begin
wenzelm@10727
    23
haftmann@24915
    24
subsection {* Least and greatest fixed points *}
haftmann@24915
    25
haftmann@26013
    26
context complete_lattice
haftmann@26013
    27
begin
haftmann@26013
    28
haftmann@24915
    29
definition
haftmann@26013
    30
  lfp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a" where
haftmann@24915
    31
  "lfp f = Inf {u. f u \<le> u}"    --{*least fixed point*}
haftmann@24915
    32
haftmann@24915
    33
definition
haftmann@26013
    34
  gfp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a" where
haftmann@24915
    35
  "gfp f = Sup {u. u \<le> f u}"    --{*greatest fixed point*}
haftmann@24915
    36
haftmann@24915
    37
haftmann@24915
    38
subsection{* Proof of Knaster-Tarski Theorem using @{term lfp} *}
haftmann@24915
    39
haftmann@24915
    40
text{*@{term "lfp f"} is the least upper bound of 
haftmann@24915
    41
      the set @{term "{u. f(u) \<le> u}"} *}
haftmann@24915
    42
haftmann@24915
    43
lemma lfp_lowerbound: "f A \<le> A ==> lfp f \<le> A"
haftmann@24915
    44
  by (auto simp add: lfp_def intro: Inf_lower)
haftmann@24915
    45
haftmann@24915
    46
lemma lfp_greatest: "(!!u. f u \<le> u ==> A \<le> u) ==> A \<le> lfp f"
haftmann@24915
    47
  by (auto simp add: lfp_def intro: Inf_greatest)
haftmann@24915
    48
haftmann@26013
    49
end
haftmann@26013
    50
haftmann@24915
    51
lemma lfp_lemma2: "mono f ==> f (lfp f) \<le> lfp f"
haftmann@24915
    52
  by (iprover intro: lfp_greatest order_trans monoD lfp_lowerbound)
haftmann@24915
    53
haftmann@24915
    54
lemma lfp_lemma3: "mono f ==> lfp f \<le> f (lfp f)"
haftmann@24915
    55
  by (iprover intro: lfp_lemma2 monoD lfp_lowerbound)
haftmann@24915
    56
haftmann@24915
    57
lemma lfp_unfold: "mono f ==> lfp f = f (lfp f)"
haftmann@24915
    58
  by (iprover intro: order_antisym lfp_lemma2 lfp_lemma3)
haftmann@24915
    59
haftmann@24915
    60
lemma lfp_const: "lfp (\<lambda>x. t) = t"
haftmann@24915
    61
  by (rule lfp_unfold) (simp add:mono_def)
haftmann@24915
    62
haftmann@24915
    63
haftmann@24915
    64
subsection {* General induction rules for least fixed points *}
haftmann@24915
    65
haftmann@24915
    66
theorem lfp_induct:
haftmann@24915
    67
  assumes mono: "mono f" and ind: "f (inf (lfp f) P) <= P"
haftmann@24915
    68
  shows "lfp f <= P"
haftmann@24915
    69
proof -
haftmann@24915
    70
  have "inf (lfp f) P <= lfp f" by (rule inf_le1)
haftmann@24915
    71
  with mono have "f (inf (lfp f) P) <= f (lfp f)" ..
haftmann@24915
    72
  also from mono have "f (lfp f) = lfp f" by (rule lfp_unfold [symmetric])
haftmann@24915
    73
  finally have "f (inf (lfp f) P) <= lfp f" .
haftmann@24915
    74
  from this and ind have "f (inf (lfp f) P) <= inf (lfp f) P" by (rule le_infI)
haftmann@24915
    75
  hence "lfp f <= inf (lfp f) P" by (rule lfp_lowerbound)
haftmann@24915
    76
  also have "inf (lfp f) P <= P" by (rule inf_le2)
haftmann@24915
    77
  finally show ?thesis .
haftmann@24915
    78
qed
haftmann@24915
    79
haftmann@24915
    80
lemma lfp_induct_set:
haftmann@24915
    81
  assumes lfp: "a: lfp(f)"
haftmann@24915
    82
      and mono: "mono(f)"
haftmann@24915
    83
      and indhyp: "!!x. [| x: f(lfp(f) Int {x. P(x)}) |] ==> P(x)"
haftmann@24915
    84
  shows "P(a)"
haftmann@24915
    85
  by (rule lfp_induct [THEN subsetD, THEN CollectD, OF mono _ lfp])
haftmann@24915
    86
    (auto simp: inf_set_eq intro: indhyp)
haftmann@24915
    87
haftmann@26013
    88
lemma lfp_ordinal_induct:
haftmann@26013
    89
  fixes f :: "'a\<Colon>complete_lattice \<Rightarrow> 'a"
haftmann@26013
    90
  assumes mono: "mono f"
haftmann@26013
    91
  and P_f: "\<And>S. P S \<Longrightarrow> P (f S)"
haftmann@26013
    92
  and P_Union: "\<And>M. \<forall>S\<in>M. P S \<Longrightarrow> P (Sup M)"
haftmann@26013
    93
  shows "P (lfp f)"
haftmann@26013
    94
proof -
haftmann@26013
    95
  let ?M = "{S. S \<le> lfp f \<and> P S}"
haftmann@26013
    96
  have "P (Sup ?M)" using P_Union by simp
haftmann@26013
    97
  also have "Sup ?M = lfp f"
haftmann@26013
    98
  proof (rule antisym)
haftmann@26013
    99
    show "Sup ?M \<le> lfp f" by (blast intro: Sup_least)
haftmann@26013
   100
    hence "f (Sup ?M) \<le> f (lfp f)" by (rule mono [THEN monoD])
haftmann@26013
   101
    hence "f (Sup ?M) \<le> lfp f" using mono [THEN lfp_unfold] by simp
haftmann@26013
   102
    hence "f (Sup ?M) \<in> ?M" using P_f P_Union by simp
haftmann@26013
   103
    hence "f (Sup ?M) \<le> Sup ?M" by (rule Sup_upper)
haftmann@26013
   104
    thus "lfp f \<le> Sup ?M" by (rule lfp_lowerbound)
haftmann@26013
   105
  qed
haftmann@26013
   106
  finally show ?thesis .
haftmann@26013
   107
qed 
haftmann@26013
   108
haftmann@26013
   109
lemma lfp_ordinal_induct_set: 
haftmann@24915
   110
  assumes mono: "mono f"
haftmann@24915
   111
  and P_f: "!!S. P S ==> P(f S)"
haftmann@24915
   112
  and P_Union: "!!M. !S:M. P S ==> P(Union M)"
haftmann@24915
   113
  shows "P(lfp f)"
berghofe@26793
   114
  using assms unfolding Sup_set_eq [symmetric]
berghofe@26793
   115
  by (rule lfp_ordinal_induct [where P=P])
haftmann@24915
   116
haftmann@24915
   117
haftmann@24915
   118
text{*Definition forms of @{text lfp_unfold} and @{text lfp_induct}, 
haftmann@24915
   119
    to control unfolding*}
haftmann@24915
   120
haftmann@24915
   121
lemma def_lfp_unfold: "[| h==lfp(f);  mono(f) |] ==> h = f(h)"
haftmann@24915
   122
by (auto intro!: lfp_unfold)
haftmann@24915
   123
haftmann@24915
   124
lemma def_lfp_induct: 
haftmann@24915
   125
    "[| A == lfp(f); mono(f);
haftmann@24915
   126
        f (inf A P) \<le> P
haftmann@24915
   127
     |] ==> A \<le> P"
haftmann@24915
   128
  by (blast intro: lfp_induct)
haftmann@24915
   129
haftmann@24915
   130
lemma def_lfp_induct_set: 
haftmann@24915
   131
    "[| A == lfp(f);  mono(f);   a:A;                    
haftmann@24915
   132
        !!x. [| x: f(A Int {x. P(x)}) |] ==> P(x)         
haftmann@24915
   133
     |] ==> P(a)"
haftmann@24915
   134
  by (blast intro: lfp_induct_set)
haftmann@24915
   135
haftmann@24915
   136
(*Monotonicity of lfp!*)
haftmann@24915
   137
lemma lfp_mono: "(!!Z. f Z \<le> g Z) ==> lfp f \<le> lfp g"
haftmann@24915
   138
  by (rule lfp_lowerbound [THEN lfp_greatest], blast intro: order_trans)
haftmann@24915
   139
haftmann@24915
   140
haftmann@24915
   141
subsection {* Proof of Knaster-Tarski Theorem using @{term gfp} *}
haftmann@24915
   142
haftmann@24915
   143
text{*@{term "gfp f"} is the greatest lower bound of 
haftmann@24915
   144
      the set @{term "{u. u \<le> f(u)}"} *}
haftmann@24915
   145
haftmann@24915
   146
lemma gfp_upperbound: "X \<le> f X ==> X \<le> gfp f"
haftmann@24915
   147
  by (auto simp add: gfp_def intro: Sup_upper)
haftmann@24915
   148
haftmann@24915
   149
lemma gfp_least: "(!!u. u \<le> f u ==> u \<le> X) ==> gfp f \<le> X"
haftmann@24915
   150
  by (auto simp add: gfp_def intro: Sup_least)
haftmann@24915
   151
haftmann@24915
   152
lemma gfp_lemma2: "mono f ==> gfp f \<le> f (gfp f)"
haftmann@24915
   153
  by (iprover intro: gfp_least order_trans monoD gfp_upperbound)
haftmann@24915
   154
haftmann@24915
   155
lemma gfp_lemma3: "mono f ==> f (gfp f) \<le> gfp f"
haftmann@24915
   156
  by (iprover intro: gfp_lemma2 monoD gfp_upperbound)
haftmann@24915
   157
haftmann@24915
   158
lemma gfp_unfold: "mono f ==> gfp f = f (gfp f)"
haftmann@24915
   159
  by (iprover intro: order_antisym gfp_lemma2 gfp_lemma3)
haftmann@24915
   160
haftmann@24915
   161
haftmann@24915
   162
subsection {* Coinduction rules for greatest fixed points *}
haftmann@24915
   163
haftmann@24915
   164
text{*weak version*}
haftmann@24915
   165
lemma weak_coinduct: "[| a: X;  X \<subseteq> f(X) |] ==> a : gfp(f)"
haftmann@24915
   166
by (rule gfp_upperbound [THEN subsetD], auto)
haftmann@24915
   167
haftmann@24915
   168
lemma weak_coinduct_image: "!!X. [| a : X; g`X \<subseteq> f (g`X) |] ==> g a : gfp f"
haftmann@24915
   169
apply (erule gfp_upperbound [THEN subsetD])
haftmann@24915
   170
apply (erule imageI)
haftmann@24915
   171
done
haftmann@24915
   172
haftmann@24915
   173
lemma coinduct_lemma:
haftmann@24915
   174
     "[| X \<le> f (sup X (gfp f));  mono f |] ==> sup X (gfp f) \<le> f (sup X (gfp f))"
haftmann@24915
   175
  apply (frule gfp_lemma2)
haftmann@24915
   176
  apply (drule mono_sup)
haftmann@24915
   177
  apply (rule le_supI)
haftmann@24915
   178
  apply assumption
haftmann@24915
   179
  apply (rule order_trans)
haftmann@24915
   180
  apply (rule order_trans)
haftmann@24915
   181
  apply assumption
haftmann@24915
   182
  apply (rule sup_ge2)
haftmann@24915
   183
  apply assumption
haftmann@24915
   184
  done
haftmann@24915
   185
haftmann@24915
   186
text{*strong version, thanks to Coen and Frost*}
haftmann@24915
   187
lemma coinduct_set: "[| mono(f);  a: X;  X \<subseteq> f(X Un gfp(f)) |] ==> a : gfp(f)"
haftmann@24915
   188
by (blast intro: weak_coinduct [OF _ coinduct_lemma, simplified sup_set_eq])
haftmann@24915
   189
haftmann@24915
   190
lemma coinduct: "[| mono(f); X \<le> f (sup X (gfp f)) |] ==> X \<le> gfp(f)"
haftmann@24915
   191
  apply (rule order_trans)
haftmann@24915
   192
  apply (rule sup_ge1)
haftmann@24915
   193
  apply (erule gfp_upperbound [OF coinduct_lemma])
haftmann@24915
   194
  apply assumption
haftmann@24915
   195
  done
haftmann@24915
   196
haftmann@24915
   197
lemma gfp_fun_UnI2: "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))"
haftmann@24915
   198
by (blast dest: gfp_lemma2 mono_Un)
haftmann@24915
   199
haftmann@24915
   200
haftmann@24915
   201
subsection {* Even Stronger Coinduction Rule, by Martin Coen *}
haftmann@24915
   202
haftmann@24915
   203
text{* Weakens the condition @{term "X \<subseteq> f(X)"} to one expressed using both
haftmann@24915
   204
  @{term lfp} and @{term gfp}*}
haftmann@24915
   205
haftmann@24915
   206
lemma coinduct3_mono_lemma: "mono(f) ==> mono(%x. f(x) Un X Un B)"
haftmann@24915
   207
by (iprover intro: subset_refl monoI Un_mono monoD)
haftmann@24915
   208
haftmann@24915
   209
lemma coinduct3_lemma:
haftmann@24915
   210
     "[| X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |]
haftmann@24915
   211
      ==> lfp(%x. f(x) Un X Un gfp(f)) \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)))"
haftmann@24915
   212
apply (rule subset_trans)
haftmann@24915
   213
apply (erule coinduct3_mono_lemma [THEN lfp_lemma3])
haftmann@24915
   214
apply (rule Un_least [THEN Un_least])
haftmann@24915
   215
apply (rule subset_refl, assumption)
haftmann@24915
   216
apply (rule gfp_unfold [THEN equalityD1, THEN subset_trans], assumption)
berghofe@26793
   217
apply (rule monoD [where f=f], assumption)
haftmann@24915
   218
apply (subst coinduct3_mono_lemma [THEN lfp_unfold], auto)
haftmann@24915
   219
done
haftmann@24915
   220
haftmann@24915
   221
lemma coinduct3: 
haftmann@24915
   222
  "[| mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)"
haftmann@24915
   223
apply (rule coinduct3_lemma [THEN [2] weak_coinduct])
haftmann@24915
   224
apply (rule coinduct3_mono_lemma [THEN lfp_unfold, THEN ssubst], auto)
haftmann@24915
   225
done
haftmann@24915
   226
haftmann@24915
   227
haftmann@24915
   228
text{*Definition forms of @{text gfp_unfold} and @{text coinduct}, 
haftmann@24915
   229
    to control unfolding*}
haftmann@24915
   230
haftmann@24915
   231
lemma def_gfp_unfold: "[| A==gfp(f);  mono(f) |] ==> A = f(A)"
haftmann@24915
   232
by (auto intro!: gfp_unfold)
haftmann@24915
   233
haftmann@24915
   234
lemma def_coinduct:
haftmann@24915
   235
     "[| A==gfp(f);  mono(f);  X \<le> f(sup X A) |] ==> X \<le> A"
haftmann@24915
   236
by (iprover intro!: coinduct)
haftmann@24915
   237
haftmann@24915
   238
lemma def_coinduct_set:
haftmann@24915
   239
     "[| A==gfp(f);  mono(f);  a:X;  X \<subseteq> f(X Un A) |] ==> a: A"
haftmann@24915
   240
by (auto intro!: coinduct_set)
haftmann@24915
   241
haftmann@24915
   242
(*The version used in the induction/coinduction package*)
haftmann@24915
   243
lemma def_Collect_coinduct:
haftmann@24915
   244
    "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));   
haftmann@24915
   245
        a: X;  !!z. z: X ==> P (X Un A) z |] ==>  
haftmann@24915
   246
     a : A"
haftmann@24915
   247
apply (erule def_coinduct_set, auto) 
haftmann@24915
   248
done
haftmann@24915
   249
haftmann@24915
   250
lemma def_coinduct3:
haftmann@24915
   251
    "[| A==gfp(f); mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un A)) |] ==> a: A"
haftmann@24915
   252
by (auto intro!: coinduct3)
haftmann@24915
   253
haftmann@24915
   254
text{*Monotonicity of @{term gfp}!*}
haftmann@24915
   255
lemma gfp_mono: "(!!Z. f Z \<le> g Z) ==> gfp f \<le> gfp g"
haftmann@24915
   256
  by (rule gfp_upperbound [THEN gfp_least], blast intro: order_trans)
haftmann@24915
   257
haftmann@24915
   258
berghofe@23734
   259
subsection {* Inductive predicates and sets *}
wenzelm@11688
   260
wenzelm@11688
   261
text {* Inversion of injective functions. *}
wenzelm@11436
   262
wenzelm@11436
   263
constdefs
wenzelm@11436
   264
  myinv :: "('a => 'b) => ('b => 'a)"
wenzelm@11436
   265
  "myinv (f :: 'a => 'b) == \<lambda>y. THE x. f x = y"
wenzelm@11436
   266
wenzelm@11436
   267
lemma myinv_f_f: "inj f ==> myinv f (f x) = x"
wenzelm@11436
   268
proof -
wenzelm@11436
   269
  assume "inj f"
wenzelm@11436
   270
  hence "(THE x'. f x' = f x) = (THE x'. x' = x)"
wenzelm@11436
   271
    by (simp only: inj_eq)
wenzelm@11436
   272
  also have "... = x" by (rule the_eq_trivial)
wenzelm@11439
   273
  finally show ?thesis by (unfold myinv_def)
wenzelm@11436
   274
qed
wenzelm@11436
   275
wenzelm@11436
   276
lemma f_myinv_f: "inj f ==> y \<in> range f ==> f (myinv f y) = y"
wenzelm@11436
   277
proof (unfold myinv_def)
wenzelm@11436
   278
  assume inj: "inj f"
wenzelm@11436
   279
  assume "y \<in> range f"
wenzelm@11436
   280
  then obtain x where "y = f x" ..
wenzelm@11436
   281
  hence x: "f x = y" ..
wenzelm@11436
   282
  thus "f (THE x. f x = y) = y"
wenzelm@11436
   283
  proof (rule theI)
wenzelm@11436
   284
    fix x' assume "f x' = y"
wenzelm@11436
   285
    with x have "f x' = f x" by simp
wenzelm@11436
   286
    with inj show "x' = x" by (rule injD)
wenzelm@11436
   287
  qed
wenzelm@11436
   288
qed
wenzelm@11436
   289
wenzelm@11436
   290
hide const myinv
wenzelm@11436
   291
wenzelm@11436
   292
wenzelm@11688
   293
text {* Package setup. *}
wenzelm@10402
   294
berghofe@23734
   295
theorems basic_monos =
haftmann@22218
   296
  subset_refl imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
wenzelm@11688
   297
  Collect_mono in_mono vimage_mono
wenzelm@11688
   298
  imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
wenzelm@11688
   299
  not_all not_ex
wenzelm@11688
   300
  Ball_def Bex_def
wenzelm@18456
   301
  induct_rulify_fallback
wenzelm@11688
   302
haftmann@24915
   303
ML {*
haftmann@24915
   304
val def_lfp_unfold = @{thm def_lfp_unfold}
haftmann@24915
   305
val def_gfp_unfold = @{thm def_gfp_unfold}
haftmann@24915
   306
val def_lfp_induct = @{thm def_lfp_induct}
haftmann@24915
   307
val def_coinduct = @{thm def_coinduct}
haftmann@25510
   308
val inf_bool_eq = @{thm inf_bool_eq} RS @{thm eq_reflection}
haftmann@25510
   309
val inf_fun_eq = @{thm inf_fun_eq} RS @{thm eq_reflection}
haftmann@25510
   310
val sup_bool_eq = @{thm sup_bool_eq} RS @{thm eq_reflection}
haftmann@25510
   311
val sup_fun_eq = @{thm sup_fun_eq} RS @{thm eq_reflection}
haftmann@24915
   312
val le_boolI = @{thm le_boolI}
haftmann@24915
   313
val le_boolI' = @{thm le_boolI'}
haftmann@24915
   314
val le_funI = @{thm le_funI}
haftmann@24915
   315
val le_boolE = @{thm le_boolE}
haftmann@24915
   316
val le_funE = @{thm le_funE}
haftmann@24915
   317
val le_boolD = @{thm le_boolD}
haftmann@24915
   318
val le_funD = @{thm le_funD}
haftmann@25510
   319
val le_bool_def = @{thm le_bool_def} RS @{thm eq_reflection}
haftmann@25510
   320
val le_fun_def = @{thm le_fun_def} RS @{thm eq_reflection}
haftmann@24915
   321
*}
haftmann@24915
   322
haftmann@31723
   323
use "Tools/inductive.ML"
haftmann@31723
   324
setup Inductive.setup
berghofe@21018
   325
berghofe@23734
   326
theorems [mono] =
haftmann@22218
   327
  imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
berghofe@21018
   328
  imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
berghofe@21018
   329
  not_all not_ex
berghofe@21018
   330
  Ball_def Bex_def
berghofe@21018
   331
  induct_rulify_fallback
berghofe@21018
   332
wenzelm@11688
   333
wenzelm@12023
   334
subsection {* Inductive datatypes and primitive recursion *}
wenzelm@11688
   335
wenzelm@11825
   336
text {* Package setup. *}
wenzelm@11825
   337
haftmann@31775
   338
use "Tools/Datatype/datatype_aux.ML"
haftmann@31775
   339
use "Tools/Datatype/datatype_prop.ML"
haftmann@31775
   340
use "Tools/Datatype/datatype_rep_proofs.ML"
haftmann@31775
   341
use "Tools/Datatype/datatype_abs_proofs.ML"
haftmann@31775
   342
use "Tools/Datatype/datatype_case.ML"
haftmann@31775
   343
use "Tools/Datatype/datatype.ML"
haftmann@31723
   344
setup Datatype.setup
haftmann@31604
   345
haftmann@31723
   346
use "Tools/old_primrec.ML"
haftmann@31723
   347
use "Tools/primrec.ML"
berghofe@12437
   348
haftmann@31775
   349
use "Tools/Datatype/datatype_codegen.ML"
haftmann@25534
   350
setup DatatypeCodegen.setup
haftmann@25534
   351
berghofe@12437
   352
use "Tools/inductive_codegen.ML"
berghofe@12437
   353
setup InductiveCodegen.setup
berghofe@12437
   354
nipkow@23526
   355
text{* Lambda-abstractions with pattern matching: *}
nipkow@23526
   356
nipkow@23526
   357
syntax
nipkow@23529
   358
  "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(%_)" 10)
nipkow@23526
   359
syntax (xsymbols)
nipkow@23529
   360
  "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(\<lambda>_)" 10)
nipkow@23526
   361
nipkow@23529
   362
parse_translation (advanced) {*
nipkow@23529
   363
let
nipkow@23529
   364
  fun fun_tr ctxt [cs] =
nipkow@23529
   365
    let
wenzelm@29281
   366
      val x = Free (Name.variant (Term.add_free_names cs []) "x", dummyT);
haftmann@31784
   367
      val ft = DatatypeCase.case_tr true Datatype.info_of_constr
nipkow@24349
   368
                 ctxt [x, cs]
nipkow@23529
   369
    in lambda x ft end
nipkow@23529
   370
in [("_lam_pats_syntax", fun_tr)] end
nipkow@23526
   371
*}
nipkow@23526
   372
nipkow@23526
   373
end