src/HOL/HOLCF/ex/Pattern_Match.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 46909 3c73a121a387
child 51717 9e7d1c139569
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42151
4da4fc77664b tuned headers;
wenzelm
parents: 42057
diff changeset
     1
(*  Title:      HOL/HOLCF/ex/Pattern_Match.thy
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     3
*)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     4
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     5
header {* An experimental pattern-matching notation *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     6
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     7
theory Pattern_Match
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     8
imports HOLCF
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
     9
begin
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    10
40329
73f2b99b549d change default_sort of HOLCF from pcpo to bifinite; rename command 'new_domain' to 'domain'; rename 'domain' to 'domain (unsafe)'
huffman
parents: 40327
diff changeset
    11
default_sort pcpo
73f2b99b549d change default_sort of HOLCF from pcpo to bifinite; rename command 'new_domain' to 'domain'; rename 'domain' to 'domain (unsafe)'
huffman
parents: 40327
diff changeset
    12
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    13
text {* FIXME: Find a proper way to un-hide constants. *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    14
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    15
abbreviation fail :: "'a match"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    16
where "fail \<equiv> Fixrec.fail"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    17
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    18
abbreviation succeed :: "'a \<rightarrow> 'a match"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    19
where "succeed \<equiv> Fixrec.succeed"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    20
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    21
abbreviation run :: "'a match \<rightarrow> 'a"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    22
where "run \<equiv> Fixrec.run"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    23
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    24
subsection {* Fatbar combinator *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    25
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    26
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    27
  fatbar :: "('a \<rightarrow> 'b match) \<rightarrow> ('a \<rightarrow> 'b match) \<rightarrow> ('a \<rightarrow> 'b match)" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    28
  "fatbar = (\<Lambda> a b x. a\<cdot>x +++ b\<cdot>x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    29
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    30
abbreviation
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    31
  fatbar_syn :: "['a \<rightarrow> 'b match, 'a \<rightarrow> 'b match] \<Rightarrow> 'a \<rightarrow> 'b match" (infixr "\<parallel>" 60)  where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    32
  "m1 \<parallel> m2 == fatbar\<cdot>m1\<cdot>m2"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    33
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    34
lemma fatbar1: "m\<cdot>x = \<bottom> \<Longrightarrow> (m \<parallel> ms)\<cdot>x = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    35
by (simp add: fatbar_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    36
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    37
lemma fatbar2: "m\<cdot>x = fail \<Longrightarrow> (m \<parallel> ms)\<cdot>x = ms\<cdot>x"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    38
by (simp add: fatbar_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    39
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    40
lemma fatbar3: "m\<cdot>x = succeed\<cdot>y \<Longrightarrow> (m \<parallel> ms)\<cdot>x = succeed\<cdot>y"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    41
by (simp add: fatbar_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    42
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    43
lemmas fatbar_simps = fatbar1 fatbar2 fatbar3
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    44
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    45
lemma run_fatbar1: "m\<cdot>x = \<bottom> \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    46
by (simp add: fatbar_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    47
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    48
lemma run_fatbar2: "m\<cdot>x = fail \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = run\<cdot>(ms\<cdot>x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    49
by (simp add: fatbar_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    50
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    51
lemma run_fatbar3: "m\<cdot>x = succeed\<cdot>y \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = y"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    52
by (simp add: fatbar_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    53
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    54
lemmas run_fatbar_simps [simp] = run_fatbar1 run_fatbar2 run_fatbar3
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    55
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    56
subsection {* Bind operator for match monad *}
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    57
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    58
definition match_bind :: "'a match \<rightarrow> ('a \<rightarrow> 'b match) \<rightarrow> 'b match" where
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    59
  "match_bind = (\<Lambda> m k. sscase\<cdot>(\<Lambda> _. fail)\<cdot>(fup\<cdot>k)\<cdot>(Rep_match m))"
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    60
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    61
lemma match_bind_simps [simp]:
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    62
  "match_bind\<cdot>\<bottom>\<cdot>k = \<bottom>"
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    63
  "match_bind\<cdot>fail\<cdot>k = fail"
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    64
  "match_bind\<cdot>(succeed\<cdot>x)\<cdot>k = k\<cdot>x"
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    65
unfolding match_bind_def fail_def succeed_def
40834
a1249aeff5b6 change cpodef-generated cont_Rep rules to cont2cont format
huffman
parents: 40774
diff changeset
    66
by (simp_all add: cont_Rep_match cont_Abs_match
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    67
  Rep_match_strict Abs_match_inverse)
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    68
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    69
subsection {* Case branch combinator *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    70
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    71
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    72
  branch :: "('a \<rightarrow> 'b match) \<Rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'c match)" where
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    73
  "branch p \<equiv> \<Lambda> r x. match_bind\<cdot>(p\<cdot>x)\<cdot>(\<Lambda> y. succeed\<cdot>(r\<cdot>y))"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    74
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    75
lemma branch_simps:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    76
  "p\<cdot>x = \<bottom> \<Longrightarrow> branch p\<cdot>r\<cdot>x = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    77
  "p\<cdot>x = fail \<Longrightarrow> branch p\<cdot>r\<cdot>x = fail"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    78
  "p\<cdot>x = succeed\<cdot>y \<Longrightarrow> branch p\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>y)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    79
by (simp_all add: branch_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    80
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    81
lemma branch_succeed [simp]: "branch succeed\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    82
by (simp add: branch_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    83
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    84
subsection {* Cases operator *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    85
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    86
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    87
  cases :: "'a match \<rightarrow> 'a::pcpo" where
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
    88
  "cases = Fixrec.run"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    89
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    90
text {* rewrite rules for cases *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    91
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    92
lemma cases_strict [simp]: "cases\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    93
by (simp add: cases_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    94
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    95
lemma cases_fail [simp]: "cases\<cdot>fail = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    96
by (simp add: cases_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    97
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    98
lemma cases_succeed [simp]: "cases\<cdot>(succeed\<cdot>x) = x"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
    99
by (simp add: cases_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   100
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   101
subsection {* Case syntax *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   102
42057
3eba96ff3d3e more selective strip_positions in case patterns -- reactivate translations based on "case _ of _" in HOL and special patterns in HOLCF;
wenzelm
parents: 41476
diff changeset
   103
nonterminal Case_pat and Case_syn and Cases_syn
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   104
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   105
syntax
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   106
  "_Case_syntax":: "['a, Cases_syn] => 'b"               ("(Case _ of/ _)" 10)
42057
3eba96ff3d3e more selective strip_positions in case patterns -- reactivate translations based on "case _ of _" in HOL and special patterns in HOLCF;
wenzelm
parents: 41476
diff changeset
   107
  "_Case1"      :: "[Case_pat, 'b] => Case_syn"          ("(2_ =>/ _)" 10)
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   108
  ""            :: "Case_syn => Cases_syn"               ("_")
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   109
  "_Case2"      :: "[Case_syn, Cases_syn] => Cases_syn"  ("_/ | _")
42057
3eba96ff3d3e more selective strip_positions in case patterns -- reactivate translations based on "case _ of _" in HOL and special patterns in HOLCF;
wenzelm
parents: 41476
diff changeset
   110
  "_strip_positions" :: "'a => Case_pat"                 ("_")
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   111
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   112
syntax (xsymbols)
42057
3eba96ff3d3e more selective strip_positions in case patterns -- reactivate translations based on "case _ of _" in HOL and special patterns in HOLCF;
wenzelm
parents: 41476
diff changeset
   113
  "_Case1"      :: "[Case_pat, 'b] => Case_syn"          ("(2_ \<Rightarrow>/ _)" 10)
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   114
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   115
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   116
  "_Case_syntax x ms" == "CONST cases\<cdot>(ms\<cdot>x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   117
  "_Case2 m ms" == "m \<parallel> ms"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   118
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   119
text {* Parsing Case expressions *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   120
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   121
syntax
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   122
  "_pat" :: "'a"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   123
  "_variable" :: "'a"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   124
  "_noargs" :: "'a"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   125
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   126
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   127
  "_Case1 p r" => "CONST branch (_pat p)\<cdot>(_variable p r)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   128
  "_variable (_args x y) r" => "CONST csplit\<cdot>(_variable x (_variable y r))"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   129
  "_variable _noargs r" => "CONST unit_when\<cdot>r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   130
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   131
parse_translation {*
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   132
(* rewrite (_pat x) => (succeed) *)
40327
1dfdbd66093a renamed {Rep,Abs}_CFun to {Rep,Abs}_cfun
huffman
parents: 40326
diff changeset
   133
(* rewrite (_variable x t) => (Abs_cfun (%x. t)) *)
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   134
 [(@{syntax_const "_pat"}, fn _ => Syntax.const @{const_syntax Fixrec.succeed}),
42284
326f57825e1a explicit structure Syntax_Trans;
wenzelm
parents: 42224
diff changeset
   135
  Syntax_Trans.mk_binder_tr (@{syntax_const "_variable"}, @{const_syntax Abs_cfun})];
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   136
*}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   137
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   138
text {* Printing Case expressions *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   139
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   140
syntax
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   141
  "_match" :: "'a"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   142
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   143
print_translation {*
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   144
  let
40327
1dfdbd66093a renamed {Rep,Abs}_CFun to {Rep,Abs}_cfun
huffman
parents: 40326
diff changeset
   145
    fun dest_LAM (Const (@{const_syntax Rep_cfun},_) $ Const (@{const_syntax unit_when},_) $ t) =
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   146
          (Syntax.const @{syntax_const "_noargs"}, t)
40327
1dfdbd66093a renamed {Rep,Abs}_CFun to {Rep,Abs}_cfun
huffman
parents: 40326
diff changeset
   147
    |   dest_LAM (Const (@{const_syntax Rep_cfun},_) $ Const (@{const_syntax csplit},_) $ t) =
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   148
          let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   149
            val (v1, t1) = dest_LAM t;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   150
            val (v2, t2) = dest_LAM t1;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   151
          in (Syntax.const @{syntax_const "_args"} $ v1 $ v2, t2) end
40327
1dfdbd66093a renamed {Rep,Abs}_CFun to {Rep,Abs}_cfun
huffman
parents: 40326
diff changeset
   152
    |   dest_LAM (Const (@{const_syntax Abs_cfun},_) $ t) =
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   153
          let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   154
            val abs =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   155
              case t of Abs abs => abs
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   156
                | _ => ("x", dummyT, incr_boundvars 1 t $ Bound 0);
42284
326f57825e1a explicit structure Syntax_Trans;
wenzelm
parents: 42224
diff changeset
   157
            val (x, t') = Syntax_Trans.atomic_abs_tr' abs;
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   158
          in (Syntax.const @{syntax_const "_variable"} $ x, t') end
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   159
    |   dest_LAM _ = raise Match; (* too few vars: abort translation *)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   160
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   161
    fun Case1_tr' [Const(@{const_syntax branch},_) $ p, r] =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   162
          let val (v, t) = dest_LAM r in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   163
            Syntax.const @{syntax_const "_Case1"} $
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   164
              (Syntax.const @{syntax_const "_match"} $ p $ v) $ t
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   165
          end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   166
40327
1dfdbd66093a renamed {Rep,Abs}_CFun to {Rep,Abs}_cfun
huffman
parents: 40326
diff changeset
   167
  in [(@{const_syntax Rep_cfun}, Case1_tr')] end;
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   168
*}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   169
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   170
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   171
  "x" <= "_match (CONST succeed) (_variable x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   172
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   173
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   174
subsection {* Pattern combinators for data constructors *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   175
41476
0fa9629aa399 types -> type_synonym
huffman
parents: 41229
diff changeset
   176
type_synonym ('a, 'b) pat = "'a \<rightarrow> 'b match"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   177
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   178
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   179
  cpair_pat :: "('a, 'c) pat \<Rightarrow> ('b, 'd) pat \<Rightarrow> ('a \<times> 'b, 'c \<times> 'd) pat" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   180
  "cpair_pat p1 p2 = (\<Lambda>(x, y).
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
   181
    match_bind\<cdot>(p1\<cdot>x)\<cdot>(\<Lambda> a. match_bind\<cdot>(p2\<cdot>y)\<cdot>(\<Lambda> b. succeed\<cdot>(a, b))))"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   182
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   183
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   184
  spair_pat ::
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   185
  "('a, 'c) pat \<Rightarrow> ('b, 'd) pat \<Rightarrow> ('a::pcpo \<otimes> 'b::pcpo, 'c \<times> 'd) pat" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   186
  "spair_pat p1 p2 = (\<Lambda>(:x, y:). cpair_pat p1 p2\<cdot>(x, y))"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   187
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   188
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   189
  sinl_pat :: "('a, 'c) pat \<Rightarrow> ('a::pcpo \<oplus> 'b::pcpo, 'c) pat" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   190
  "sinl_pat p = sscase\<cdot>p\<cdot>(\<Lambda> x. fail)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   191
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   192
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   193
  sinr_pat :: "('b, 'c) pat \<Rightarrow> ('a::pcpo \<oplus> 'b::pcpo, 'c) pat" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   194
  "sinr_pat p = sscase\<cdot>(\<Lambda> x. fail)\<cdot>p"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   195
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   196
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   197
  up_pat :: "('a, 'b) pat \<Rightarrow> ('a u, 'b) pat" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   198
  "up_pat p = fup\<cdot>p"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   199
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   200
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   201
  TT_pat :: "(tr, unit) pat" where
40322
707eb30e8a53 make syntax of continuous if-then-else consistent with HOL if-then-else
huffman
parents: 40026
diff changeset
   202
  "TT_pat = (\<Lambda> b. If b then succeed\<cdot>() else fail)"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   203
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   204
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   205
  FF_pat :: "(tr, unit) pat" where
40322
707eb30e8a53 make syntax of continuous if-then-else consistent with HOL if-then-else
huffman
parents: 40026
diff changeset
   206
  "FF_pat = (\<Lambda> b. If b then fail else succeed\<cdot>())"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   207
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   208
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   209
  ONE_pat :: "(one, unit) pat" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   210
  "ONE_pat = (\<Lambda> ONE. succeed\<cdot>())"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   211
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   212
text {* Parse translations (patterns) *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   213
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   214
  "_pat (XCONST Pair x y)" => "CONST cpair_pat (_pat x) (_pat y)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   215
  "_pat (XCONST spair\<cdot>x\<cdot>y)" => "CONST spair_pat (_pat x) (_pat y)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   216
  "_pat (XCONST sinl\<cdot>x)" => "CONST sinl_pat (_pat x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   217
  "_pat (XCONST sinr\<cdot>x)" => "CONST sinr_pat (_pat x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   218
  "_pat (XCONST up\<cdot>x)" => "CONST up_pat (_pat x)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   219
  "_pat (XCONST TT)" => "CONST TT_pat"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   220
  "_pat (XCONST FF)" => "CONST FF_pat"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   221
  "_pat (XCONST ONE)" => "CONST ONE_pat"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   222
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   223
text {* CONST version is also needed for constructors with special syntax *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   224
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   225
  "_pat (CONST Pair x y)" => "CONST cpair_pat (_pat x) (_pat y)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   226
  "_pat (CONST spair\<cdot>x\<cdot>y)" => "CONST spair_pat (_pat x) (_pat y)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   227
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   228
text {* Parse translations (variables) *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   229
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   230
  "_variable (XCONST Pair x y) r" => "_variable (_args x y) r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   231
  "_variable (XCONST spair\<cdot>x\<cdot>y) r" => "_variable (_args x y) r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   232
  "_variable (XCONST sinl\<cdot>x) r" => "_variable x r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   233
  "_variable (XCONST sinr\<cdot>x) r" => "_variable x r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   234
  "_variable (XCONST up\<cdot>x) r" => "_variable x r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   235
  "_variable (XCONST TT) r" => "_variable _noargs r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   236
  "_variable (XCONST FF) r" => "_variable _noargs r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   237
  "_variable (XCONST ONE) r" => "_variable _noargs r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   238
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   239
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   240
  "_variable (CONST Pair x y) r" => "_variable (_args x y) r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   241
  "_variable (CONST spair\<cdot>x\<cdot>y) r" => "_variable (_args x y) r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   242
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   243
text {* Print translations *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   244
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   245
  "CONST Pair (_match p1 v1) (_match p2 v2)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   246
      <= "_match (CONST cpair_pat p1 p2) (_args v1 v2)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   247
  "CONST spair\<cdot>(_match p1 v1)\<cdot>(_match p2 v2)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   248
      <= "_match (CONST spair_pat p1 p2) (_args v1 v2)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   249
  "CONST sinl\<cdot>(_match p1 v1)" <= "_match (CONST sinl_pat p1) v1"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   250
  "CONST sinr\<cdot>(_match p1 v1)" <= "_match (CONST sinr_pat p1) v1"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   251
  "CONST up\<cdot>(_match p1 v1)" <= "_match (CONST up_pat p1) v1"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   252
  "CONST TT" <= "_match (CONST TT_pat) _noargs"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   253
  "CONST FF" <= "_match (CONST FF_pat) _noargs"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   254
  "CONST ONE" <= "_match (CONST ONE_pat) _noargs"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   255
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   256
lemma cpair_pat1:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   257
  "branch p\<cdot>r\<cdot>x = \<bottom> \<Longrightarrow> branch (cpair_pat p q)\<cdot>(csplit\<cdot>r)\<cdot>(x, y) = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   258
apply (simp add: branch_def cpair_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   259
apply (cases "p\<cdot>x", simp_all)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   260
done
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   261
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   262
lemma cpair_pat2:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   263
  "branch p\<cdot>r\<cdot>x = fail \<Longrightarrow> branch (cpair_pat p q)\<cdot>(csplit\<cdot>r)\<cdot>(x, y) = fail"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   264
apply (simp add: branch_def cpair_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   265
apply (cases "p\<cdot>x", simp_all)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   266
done
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   267
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   268
lemma cpair_pat3:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   269
  "branch p\<cdot>r\<cdot>x = succeed\<cdot>s \<Longrightarrow>
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   270
   branch (cpair_pat p q)\<cdot>(csplit\<cdot>r)\<cdot>(x, y) = branch q\<cdot>s\<cdot>y"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   271
apply (simp add: branch_def cpair_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   272
apply (cases "p\<cdot>x", simp_all)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   273
apply (cases "q\<cdot>y", simp_all)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   274
done
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   275
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   276
lemmas cpair_pat [simp] =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   277
  cpair_pat1 cpair_pat2 cpair_pat3
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   278
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   279
lemma spair_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   280
  "branch (spair_pat p1 p2)\<cdot>r\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   281
  "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk>
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   282
     \<Longrightarrow> branch (spair_pat p1 p2)\<cdot>r\<cdot>(:x, y:) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   283
         branch (cpair_pat p1 p2)\<cdot>r\<cdot>(x, y)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   284
by (simp_all add: branch_def spair_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   285
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   286
lemma sinl_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   287
  "branch (sinl_pat p)\<cdot>r\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   288
  "x \<noteq> \<bottom> \<Longrightarrow> branch (sinl_pat p)\<cdot>r\<cdot>(sinl\<cdot>x) = branch p\<cdot>r\<cdot>x"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   289
  "y \<noteq> \<bottom> \<Longrightarrow> branch (sinl_pat p)\<cdot>r\<cdot>(sinr\<cdot>y) = fail"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   290
by (simp_all add: branch_def sinl_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   291
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   292
lemma sinr_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   293
  "branch (sinr_pat p)\<cdot>r\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   294
  "x \<noteq> \<bottom> \<Longrightarrow> branch (sinr_pat p)\<cdot>r\<cdot>(sinl\<cdot>x) = fail"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   295
  "y \<noteq> \<bottom> \<Longrightarrow> branch (sinr_pat p)\<cdot>r\<cdot>(sinr\<cdot>y) = branch p\<cdot>r\<cdot>y"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   296
by (simp_all add: branch_def sinr_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   297
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   298
lemma up_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   299
  "branch (up_pat p)\<cdot>r\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   300
  "branch (up_pat p)\<cdot>r\<cdot>(up\<cdot>x) = branch p\<cdot>r\<cdot>x"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   301
by (simp_all add: branch_def up_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   302
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   303
lemma TT_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   304
  "branch TT_pat\<cdot>(unit_when\<cdot>r)\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   305
  "branch TT_pat\<cdot>(unit_when\<cdot>r)\<cdot>TT = succeed\<cdot>r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   306
  "branch TT_pat\<cdot>(unit_when\<cdot>r)\<cdot>FF = fail"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   307
by (simp_all add: branch_def TT_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   308
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   309
lemma FF_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   310
  "branch FF_pat\<cdot>(unit_when\<cdot>r)\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   311
  "branch FF_pat\<cdot>(unit_when\<cdot>r)\<cdot>TT = fail"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   312
  "branch FF_pat\<cdot>(unit_when\<cdot>r)\<cdot>FF = succeed\<cdot>r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   313
by (simp_all add: branch_def FF_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   314
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   315
lemma ONE_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   316
  "branch ONE_pat\<cdot>(unit_when\<cdot>r)\<cdot>\<bottom> = \<bottom>"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   317
  "branch ONE_pat\<cdot>(unit_when\<cdot>r)\<cdot>ONE = succeed\<cdot>r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   318
by (simp_all add: branch_def ONE_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   319
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   320
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   321
subsection {* Wildcards, as-patterns, and lazy patterns *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   322
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   323
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   324
  wild_pat :: "'a \<rightarrow> unit match" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   325
  "wild_pat = (\<Lambda> x. succeed\<cdot>())"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   326
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   327
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   328
  as_pat :: "('a \<rightarrow> 'b match) \<Rightarrow> 'a \<rightarrow> ('a \<times> 'b) match" where
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
   329
  "as_pat p = (\<Lambda> x. match_bind\<cdot>(p\<cdot>x)\<cdot>(\<Lambda> a. succeed\<cdot>(x, a)))"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   330
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   331
definition
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   332
  lazy_pat :: "('a \<rightarrow> 'b::pcpo match) \<Rightarrow> ('a \<rightarrow> 'b match)" where
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   333
  "lazy_pat p = (\<Lambda> x. succeed\<cdot>(cases\<cdot>(p\<cdot>x)))"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   334
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   335
text {* Parse translations (patterns) *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   336
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   337
  "_pat _" => "CONST wild_pat"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   338
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   339
text {* Parse translations (variables) *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   340
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   341
  "_variable _ r" => "_variable _noargs r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   342
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   343
text {* Print translations *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   344
translations
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   345
  "_" <= "_match (CONST wild_pat) _noargs"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   346
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   347
lemma wild_pat [simp]: "branch wild_pat\<cdot>(unit_when\<cdot>r)\<cdot>x = succeed\<cdot>r"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   348
by (simp add: branch_def wild_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   349
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   350
lemma as_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   351
  "branch (as_pat p)\<cdot>(csplit\<cdot>r)\<cdot>x = branch p\<cdot>(r\<cdot>x)\<cdot>x"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   352
apply (simp add: branch_def as_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   353
apply (cases "p\<cdot>x", simp_all)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   354
done
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   355
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   356
lemma lazy_pat [simp]:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   357
  "branch p\<cdot>r\<cdot>x = \<bottom> \<Longrightarrow> branch (lazy_pat p)\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>\<bottom>)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   358
  "branch p\<cdot>r\<cdot>x = fail \<Longrightarrow> branch (lazy_pat p)\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>\<bottom>)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   359
  "branch p\<cdot>r\<cdot>x = succeed\<cdot>s \<Longrightarrow> branch (lazy_pat p)\<cdot>r\<cdot>x = succeed\<cdot>s"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   360
apply (simp_all add: branch_def lazy_pat_def)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   361
apply (cases "p\<cdot>x", simp_all)+
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   362
done
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   363
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   364
subsection {* Examples *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   365
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   366
term "Case t of (:up\<cdot>(sinl\<cdot>x), sinr\<cdot>y:) \<Rightarrow> (x, y)"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   367
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   368
term "\<Lambda> t. Case t of up\<cdot>(sinl\<cdot>a) \<Rightarrow> a | up\<cdot>(sinr\<cdot>b) \<Rightarrow> b"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   369
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   370
term "\<Lambda> t. Case t of (:up\<cdot>(sinl\<cdot>_), sinr\<cdot>x:) \<Rightarrow> x"
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   371
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   372
subsection {* ML code for generating definitions *}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   373
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   374
ML {*
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   375
local open HOLCF_Library in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   376
40026
8f8f18a88685 remove last few dependencies on domain_library.ML and delete it; temporarily disable emptiness check
huffman
parents: 39557
diff changeset
   377
infixr 6 ->>;
8f8f18a88685 remove last few dependencies on domain_library.ML and delete it; temporarily disable emptiness check
huffman
parents: 39557
diff changeset
   378
infix 9 ` ;
8f8f18a88685 remove last few dependencies on domain_library.ML and delete it; temporarily disable emptiness check
huffman
parents: 39557
diff changeset
   379
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   380
val beta_rules =
40326
73d45866dbda renamed lemma cont2cont_Rep_CFun to cont2cont_APP
huffman
parents: 40322
diff changeset
   381
  @{thms beta_cfun cont_id cont_const cont2cont_APP cont2cont_LAM'} @
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   382
  @{thms cont2cont_fst cont2cont_snd cont2cont_Pair};
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   383
45654
cf10bde35973 more antiquotations;
wenzelm
parents: 43324
diff changeset
   384
val beta_ss = HOL_basic_ss addsimps (@{thms simp_thms} @ beta_rules);
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   385
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   386
fun define_consts
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   387
    (specs : (binding * term * mixfix) list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   388
    (thy : theory)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   389
    : (term list * thm list) * theory =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   390
  let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   391
    fun mk_decl (b, t, mx) = (b, fastype_of t, mx);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   392
    val decls = map mk_decl specs;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   393
    val thy = Cont_Consts.add_consts decls thy;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   394
    fun mk_const (b, T, mx) = Const (Sign.full_name thy b, T);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   395
    val consts = map mk_const decls;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   396
    fun mk_def c (b, t, mx) =
46909
3c73a121a387 more explicit indication of def names;
wenzelm
parents: 45654
diff changeset
   397
      (Thm.def_binding b, Logic.mk_equals (c, t));
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   398
    val defs = map2 mk_def consts specs;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   399
    val (def_thms, thy) =
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 37109
diff changeset
   400
      Global_Theory.add_defs false (map Thm.no_attributes defs) thy;
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   401
  in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   402
    ((consts, def_thms), thy)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   403
  end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   404
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   405
fun prove
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   406
    (thy : theory)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   407
    (defs : thm list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   408
    (goal : term)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   409
    (tacs : {prems: thm list, context: Proof.context} -> tactic list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   410
    : thm =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   411
  let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   412
    fun tac {prems, context} =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   413
      rewrite_goals_tac defs THEN
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   414
      EVERY (tacs {prems = map (rewrite_rule defs) prems, context = context})
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   415
  in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   416
    Goal.prove_global thy [] [] goal tac
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   417
  end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   418
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   419
fun get_vars_avoiding
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   420
    (taken : string list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   421
    (args : (bool * typ) list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   422
    : (term list * term list) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   423
  let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   424
    val Ts = map snd args;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   425
    val ns = Name.variant_list taken (Datatype_Prop.make_tnames Ts);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   426
    val vs = map Free (ns ~~ Ts);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   427
    val nonlazy = map snd (filter_out (fst o fst) (args ~~ vs));
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   428
  in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   429
    (vs, nonlazy)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   430
  end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   431
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   432
(******************************************************************************)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   433
(************** definitions and theorems for pattern combinators **************)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   434
(******************************************************************************)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   435
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   436
fun add_pattern_combinators
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   437
    (bindings : binding list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   438
    (spec : (term * (bool * typ) list) list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   439
    (lhsT : typ)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   440
    (exhaust : thm)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   441
    (case_const : typ -> term)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   442
    (case_rews : thm list)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   443
    (thy : theory) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   444
  let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   445
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   446
    (* utility functions *)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   447
    fun mk_pair_pat (p1, p2) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   448
      let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   449
        val T1 = fastype_of p1;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   450
        val T2 = fastype_of p2;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   451
        val (U1, V1) = apsnd dest_matchT (dest_cfunT T1);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   452
        val (U2, V2) = apsnd dest_matchT (dest_cfunT T2);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   453
        val pat_typ = [T1, T2] --->
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   454
            (mk_prodT (U1, U2) ->> mk_matchT (mk_prodT (V1, V2)));
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   455
        val pat_const = Const (@{const_name cpair_pat}, pat_typ);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   456
      in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   457
        pat_const $ p1 $ p2
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   458
      end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   459
    fun mk_tuple_pat [] = succeed_const HOLogic.unitT
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   460
      | mk_tuple_pat ps = foldr1 mk_pair_pat ps;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   461
    fun branch_const (T,U,V) = 
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   462
      Const (@{const_name branch},
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   463
        (T ->> mk_matchT U) --> (U ->> V) ->> T ->> mk_matchT V);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   464
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   465
    (* define pattern combinators *)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   466
    local
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   467
      val tns = map (fst o dest_TFree) (snd (dest_Type lhsT));
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   468
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   469
      fun pat_eqn (i, (bind, (con, args))) : binding * term * mixfix =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   470
        let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   471
          val pat_bind = Binding.suffix_name "_pat" bind;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   472
          val Ts = map snd args;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   473
          val Vs =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   474
              (map (K "'t") args)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   475
              |> Datatype_Prop.indexify_names
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   476
              |> Name.variant_list tns
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   477
              |> map (fn t => TFree (t, @{sort pcpo}));
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   478
          val patNs = Datatype_Prop.indexify_names (map (K "pat") args);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   479
          val patTs = map2 (fn T => fn V => T ->> mk_matchT V) Ts Vs;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   480
          val pats = map Free (patNs ~~ patTs);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   481
          val fail = mk_fail (mk_tupleT Vs);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   482
          val (vs, nonlazy) = get_vars_avoiding patNs args;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   483
          val rhs = big_lambdas vs (mk_tuple_pat pats ` mk_tuple vs);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   484
          fun one_fun (j, (_, args')) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   485
            let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   486
              val (vs', nonlazy) = get_vars_avoiding patNs args';
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   487
            in if i = j then rhs else big_lambdas vs' fail end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   488
          val funs = map_index one_fun spec;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   489
          val body = list_ccomb (case_const (mk_matchT (mk_tupleT Vs)), funs);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   490
        in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   491
          (pat_bind, lambdas pats body, NoSyn)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   492
        end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   493
    in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   494
      val ((pat_consts, pat_defs), thy) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   495
          define_consts (map_index pat_eqn (bindings ~~ spec)) thy
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   496
    end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   497
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   498
    (* syntax translations for pattern combinators *)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   499
    local
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42284
diff changeset
   500
      fun syntax c = Lexicon.mark_const (fst (dest_Const c));
42224
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   501
      fun app s (l, r) = Ast.mk_appl (Ast.Constant s) [l, r];
40327
1dfdbd66093a renamed {Rep,Abs}_CFun to {Rep,Abs}_cfun
huffman
parents: 40326
diff changeset
   502
      val capp = app @{const_syntax Rep_cfun};
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   503
      val capps = Library.foldl capp
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   504
42224
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   505
      fun app_var x = Ast.mk_appl (Ast.Constant "_variable") [x, Ast.Variable "rhs"];
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   506
      fun app_pat x = Ast.mk_appl (Ast.Constant "_pat") [x];
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   507
      fun args_list [] = Ast.Constant "_noargs"
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   508
        | args_list xs = foldr1 (app "_args") xs;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   509
      fun one_case_trans (pat, (con, args)) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   510
        let
42224
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   511
          val cname = Ast.Constant (syntax con);
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   512
          val pname = Ast.Constant (syntax pat);
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   513
          val ns = 1 upto length args;
42224
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   514
          val xs = map (fn n => Ast.Variable ("x"^(string_of_int n))) ns;
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   515
          val ps = map (fn n => Ast.Variable ("p"^(string_of_int n))) ns;
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   516
          val vs = map (fn n => Ast.Variable ("v"^(string_of_int n))) ns;
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   517
        in
42224
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   518
          [Syntax.Parse_Rule (app_pat (capps (cname, xs)),
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   519
            Ast.mk_appl pname (map app_pat xs)),
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   520
           Syntax.Parse_Rule (app_var (capps (cname, xs)),
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   521
            app_var (args_list xs)),
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   522
           Syntax.Print_Rule (capps (cname, ListPair.map (app "_match") (ps,vs)),
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   523
            app "_match" (Ast.mk_appl pname ps, args_list vs))]
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   524
        end;
42224
578a51fae383 discontinued special treatment of structure Ast: no pervasive content, no inclusion in structure Syntax;
wenzelm
parents: 42204
diff changeset
   525
      val trans_rules : Ast.ast Syntax.trrule list =
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   526
          maps one_case_trans (pat_consts ~~ spec);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   527
    in
42204
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42151
diff changeset
   528
      val thy = Sign.add_trrules trans_rules thy;
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   529
    end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   530
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   531
    (* prove strictness and reduction rules of pattern combinators *)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   532
    local
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   533
      val tns = map (fst o dest_TFree) (snd (dest_Type lhsT));
43324
2b47822868e4 discontinued Name.variant to emphasize that this is old-style / indirect;
wenzelm
parents: 42290
diff changeset
   534
      val rn = singleton (Name.variant_list tns) "'r";
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   535
      val R = TFree (rn, @{sort pcpo});
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   536
      fun pat_lhs (pat, args) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   537
        let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   538
          val Ts = map snd args;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   539
          val Vs =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   540
              (map (K "'t") args)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   541
              |> Datatype_Prop.indexify_names
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   542
              |> Name.variant_list (rn::tns)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   543
              |> map (fn t => TFree (t, @{sort pcpo}));
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   544
          val patNs = Datatype_Prop.indexify_names (map (K "pat") args);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   545
          val patTs = map2 (fn T => fn V => T ->> mk_matchT V) Ts Vs;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   546
          val pats = map Free (patNs ~~ patTs);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   547
          val k = Free ("rhs", mk_tupleT Vs ->> R);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   548
          val branch1 = branch_const (lhsT, mk_tupleT Vs, R);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   549
          val fun1 = (branch1 $ list_comb (pat, pats)) ` k;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   550
          val branch2 = branch_const (mk_tupleT Ts, mk_tupleT Vs, R);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   551
          val fun2 = (branch2 $ mk_tuple_pat pats) ` k;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   552
          val taken = "rhs" :: patNs;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   553
        in (fun1, fun2, taken) end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   554
      fun pat_strict (pat, (con, args)) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   555
        let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   556
          val (fun1, fun2, taken) = pat_lhs (pat, args);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   557
          val defs = @{thm branch_def} :: pat_defs;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   558
          val goal = mk_trp (mk_strict fun1);
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
   559
          val rules = @{thms match_bind_simps} @ case_rews;
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   560
          val tacs = [simp_tac (beta_ss addsimps rules) 1];
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   561
        in prove thy defs goal (K tacs) end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   562
      fun pat_apps (i, (pat, (con, args))) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   563
        let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   564
          val (fun1, fun2, taken) = pat_lhs (pat, args);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   565
          fun pat_app (j, (con', args')) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   566
            let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   567
              val (vs, nonlazy) = get_vars_avoiding taken args';
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   568
              val con_app = list_ccomb (con', vs);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   569
              val assms = map (mk_trp o mk_defined) nonlazy;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   570
              val rhs = if i = j then fun2 ` mk_tuple vs else mk_fail R;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   571
              val concl = mk_trp (mk_eq (fun1 ` con_app, rhs));
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   572
              val goal = Logic.list_implies (assms, concl);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   573
              val defs = @{thm branch_def} :: pat_defs;
40735
6f65843e78f3 remove case combinator for fixrec match type
huffman
parents: 40329
diff changeset
   574
              val rules = @{thms match_bind_simps} @ case_rews;
37109
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   575
              val tacs = [asm_simp_tac (beta_ss addsimps rules) 1];
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   576
            in prove thy defs goal (K tacs) end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   577
        in map_index pat_app spec end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   578
    in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   579
      val pat_stricts = map pat_strict (pat_consts ~~ spec);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   580
      val pat_apps = flat (map_index pat_apps (pat_consts ~~ spec));
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   581
    end;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   582
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   583
  in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   584
    (pat_stricts @ pat_apps, thy)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   585
  end
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   586
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   587
end
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   588
*}
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   589
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   590
(*
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   591
Cut from HOLCF/Tools/domain_constructors.ML
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   592
in function add_domain_constructors:
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   593
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   594
    ( * define and prove theorems for pattern combinators * )
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   595
    val (pat_thms : thm list, thy : theory) =
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   596
      let
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   597
        val bindings = map #1 spec;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   598
        fun prep_arg (lazy, sel, T) = (lazy, T);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   599
        fun prep_con c (b, args, mx) = (c, map prep_arg args);
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   600
        val pat_spec = map2 prep_con con_consts spec;
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   601
      in
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   602
        add_pattern_combinators bindings pat_spec lhsT
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   603
          exhaust case_const cases thy
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   604
      end
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   605
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   606
*)
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   607
e67760c1b851 move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
diff changeset
   608
end