author | huffman |
Mon, 02 Nov 2009 18:39:41 -0800 | |
changeset 33401 | fc43fa403a69 |
parent 33004 | 715566791eb0 |
child 33425 | 7e4f3c66190d |
permissions | -rw-r--r-- |
31738
7b9b9ba532ca
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
1 |
(* Title: HOLCF/Tools/fixrec.ML |
23152 | 2 |
Author: Amber Telfer and Brian Huffman |
3 |
||
4 |
Recursive function definition package for HOLCF. |
|
5 |
*) |
|
6 |
||
31738
7b9b9ba532ca
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
7 |
signature FIXREC = |
23152 | 8 |
sig |
30485 | 9 |
val add_fixrec: bool -> (binding * typ option * mixfix) list |
10 |
-> (Attrib.binding * term) list -> local_theory -> local_theory |
|
11 |
val add_fixrec_cmd: bool -> (binding * string option * mixfix) list |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
12 |
-> (Attrib.binding * string) list -> local_theory -> local_theory |
30485 | 13 |
val add_fixpat: Thm.binding * term list -> theory -> theory |
14 |
val add_fixpat_cmd: Attrib.binding * string list -> theory -> theory |
|
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
15 |
val add_matchers: (string * string) list -> theory -> theory |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
16 |
val setup: theory -> theory |
23152 | 17 |
end; |
18 |
||
31738
7b9b9ba532ca
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
19 |
structure Fixrec :> FIXREC = |
23152 | 20 |
struct |
21 |
||
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
22 |
val def_cont_fix_eq = @{thm def_cont_fix_eq}; |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
23 |
val def_cont_fix_ind = @{thm def_cont_fix_ind}; |
23152 | 24 |
|
25 |
||
26 |
fun fixrec_err s = error ("fixrec definition error:\n" ^ s); |
|
27 |
fun fixrec_eq_err thy s eq = |
|
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26343
diff
changeset
|
28 |
fixrec_err (s ^ "\nin\n" ^ quote (Syntax.string_of_term_global thy eq)); |
23152 | 29 |
|
30132 | 30 |
(*************************************************************************) |
31 |
(***************************** building types ****************************) |
|
32 |
(*************************************************************************) |
|
33 |
||
23152 | 34 |
(* ->> is taken from holcf_logic.ML *) |
30132 | 35 |
fun cfunT (T, U) = Type(@{type_name "->"}, [T, U]); |
36 |
||
37 |
infixr 6 ->>; val (op ->>) = cfunT; |
|
38 |
||
39 |
fun dest_cfunT (Type(@{type_name "->"}, [T, U])) = (T, U) |
|
40 |
| dest_cfunT T = raise TYPE ("dest_cfunT", [T], []); |
|
41 |
||
42 |
fun maybeT T = Type(@{type_name "maybe"}, [T]); |
|
43 |
||
44 |
fun dest_maybeT (Type(@{type_name "maybe"}, [T])) = T |
|
45 |
| dest_maybeT T = raise TYPE ("dest_maybeT", [T], []); |
|
46 |
||
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
47 |
fun tupleT [] = HOLogic.unitT |
30132 | 48 |
| tupleT [T] = T |
49 |
| tupleT (T :: Ts) = HOLogic.mk_prodT (T, tupleT Ts); |
|
50 |
||
33401
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
51 |
local |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
52 |
|
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
53 |
fun binder_cfun (Type(@{type_name "->"},[T, U])) = T :: binder_cfun U |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
54 |
| binder_cfun (Type(@{type_name "fun"},[T, U])) = T :: binder_cfun U |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
55 |
| binder_cfun _ = []; |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
56 |
|
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
57 |
fun body_cfun (Type(@{type_name "->"},[T, U])) = body_cfun U |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
58 |
| body_cfun (Type(@{type_name "fun"},[T, U])) = body_cfun U |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
59 |
| body_cfun T = T; |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
60 |
|
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
61 |
fun strip_cfun T : typ list * typ = |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
62 |
(binder_cfun T, body_cfun T); |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
63 |
|
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
64 |
fun cfunsT (Ts, U) = List.foldr cfunT U Ts; |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
65 |
|
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
66 |
in |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
67 |
|
30912
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30485
diff
changeset
|
68 |
fun matchT (T, U) = |
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30485
diff
changeset
|
69 |
body_cfun T ->> cfunsT (binder_cfun T, U) ->> U; |
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30485
diff
changeset
|
70 |
|
33401
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
71 |
end |
30132 | 72 |
|
73 |
(*************************************************************************) |
|
74 |
(***************************** building terms ****************************) |
|
75 |
(*************************************************************************) |
|
23152 | 76 |
|
77 |
val mk_trp = HOLogic.mk_Trueprop; |
|
78 |
||
79 |
(* splits a cterm into the right and lefthand sides of equality *) |
|
80 |
fun dest_eqs t = HOLogic.dest_eq (HOLogic.dest_Trueprop t); |
|
81 |
||
82 |
(* similar to Thm.head_of, but for continuous application *) |
|
26045 | 83 |
fun chead_of (Const(@{const_name Rep_CFun},_)$f$t) = chead_of f |
23152 | 84 |
| chead_of u = u; |
85 |
||
30132 | 86 |
fun capply_const (S, T) = |
87 |
Const(@{const_name Rep_CFun}, (S ->> T) --> (S --> T)); |
|
88 |
||
89 |
fun cabs_const (S, T) = |
|
90 |
Const(@{const_name Abs_CFun}, (S --> T) --> (S ->> T)); |
|
91 |
||
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
92 |
fun mk_cabs t = |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
93 |
let val T = Term.fastype_of t |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
94 |
in cabs_const (Term.domain_type T, Term.range_type T) $ t end |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
95 |
|
30132 | 96 |
fun mk_capply (t, u) = |
97 |
let val (S, T) = |
|
98 |
case Term.fastype_of t of |
|
99 |
Type(@{type_name "->"}, [S, T]) => (S, T) |
|
100 |
| _ => raise TERM ("mk_capply " ^ ML_Syntax.print_list ML_Syntax.print_term [t, u], [t, u]); |
|
101 |
in capply_const (S, T) $ t $ u end; |
|
102 |
||
103 |
infix 0 ==; val (op ==) = Logic.mk_equals; |
|
104 |
infix 1 ===; val (op ===) = HOLogic.mk_eq; |
|
105 |
infix 9 ` ; val (op `) = mk_capply; |
|
106 |
||
23152 | 107 |
(* builds the expression (LAM v. rhs) *) |
30132 | 108 |
fun big_lambda v rhs = |
109 |
cabs_const (Term.fastype_of v, Term.fastype_of rhs) $ Term.lambda v rhs; |
|
23152 | 110 |
|
111 |
(* builds the expression (LAM v1 v2 .. vn. rhs) *) |
|
112 |
fun big_lambdas [] rhs = rhs |
|
113 |
| big_lambdas (v::vs) rhs = big_lambda v (big_lambdas vs rhs); |
|
114 |
||
30132 | 115 |
fun mk_return t = |
116 |
let val T = Term.fastype_of t |
|
117 |
in Const(@{const_name Fixrec.return}, T ->> maybeT T) ` t end; |
|
118 |
||
119 |
fun mk_bind (t, u) = |
|
120 |
let val (T, mU) = dest_cfunT (Term.fastype_of u); |
|
121 |
val bindT = maybeT T ->> (T ->> mU) ->> mU; |
|
122 |
in Const(@{const_name Fixrec.bind}, bindT) ` t ` u end; |
|
123 |
||
124 |
fun mk_mplus (t, u) = |
|
125 |
let val mT = Term.fastype_of t |
|
126 |
in Const(@{const_name Fixrec.mplus}, mT ->> mT ->> mT) ` t ` u end; |
|
127 |
||
128 |
fun mk_run t = |
|
129 |
let val mT = Term.fastype_of t |
|
130 |
val T = dest_maybeT mT |
|
131 |
in Const(@{const_name Fixrec.run}, mT ->> T) ` t end; |
|
132 |
||
133 |
fun mk_fix t = |
|
134 |
let val (T, _) = dest_cfunT (Term.fastype_of t) |
|
135 |
in Const(@{const_name fix}, (T ->> T) ->> T) ` t end; |
|
23152 | 136 |
|
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
137 |
fun mk_cont t = |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
138 |
let val T = Term.fastype_of t |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
139 |
in Const(@{const_name cont}, T --> HOLogic.boolT) $ t end; |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
140 |
|
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
141 |
val mk_fst = HOLogic.mk_fst |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
142 |
val mk_snd = HOLogic.mk_snd |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
143 |
|
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
144 |
(* builds the expression (v1,v2,..,vn) *) |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
145 |
fun mk_tuple [] = HOLogic.unit |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
146 |
| mk_tuple (t::[]) = t |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
147 |
| mk_tuple (t::ts) = HOLogic.mk_prod (t, mk_tuple ts); |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
148 |
|
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
149 |
(* builds the expression (%(v1,v2,..,vn). rhs) *) |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
150 |
fun lambda_tuple [] rhs = Term.lambda (Free("unit", HOLogic.unitT)) rhs |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
151 |
| lambda_tuple (v::[]) rhs = Term.lambda v rhs |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
152 |
| lambda_tuple (v::vs) rhs = |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
153 |
HOLogic.mk_split (Term.lambda v (lambda_tuple vs rhs)); |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
154 |
|
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
155 |
|
23152 | 156 |
(*************************************************************************) |
157 |
(************* fixed-point definitions and unfolding theorems ************) |
|
158 |
(*************************************************************************) |
|
159 |
||
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
160 |
fun add_fixdefs |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
161 |
(fixes : ((binding * typ) * mixfix) list) |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
162 |
(spec : (Attrib.binding * term) list) |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
163 |
(lthy : local_theory) = |
23152 | 164 |
let |
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
165 |
val thy = ProofContext.theory_of lthy; |
30223
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
30211
diff
changeset
|
166 |
val names = map (Binding.name_of o fst o fst) fixes; |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
167 |
val all_names = space_implode "_" names; |
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
31740
diff
changeset
|
168 |
val (lhss, rhss) = ListPair.unzip (map (dest_eqs o snd) spec); |
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
169 |
val functional = lambda_tuple lhss (mk_tuple rhss); |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
170 |
val fixpoint = mk_fix (mk_cabs functional); |
23152 | 171 |
|
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
172 |
val cont_thm = |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
173 |
Goal.prove lthy [] [] (mk_trp (mk_cont functional)) |
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
31740
diff
changeset
|
174 |
(K (simp_tac (simpset_of lthy) 1)); |
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
175 |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
176 |
fun one_def (l as Free(n,_)) r = |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
177 |
let val b = Long_Name.base_name n |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
178 |
in ((Binding.name (b^"_def"), []), r) end |
23152 | 179 |
| one_def _ _ = fixrec_err "fixdefs: lhs not of correct form"; |
180 |
fun defs [] _ = [] |
|
181 |
| defs (l::[]) r = [one_def l r] |
|
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
182 |
| defs (l::ls) r = one_def l (mk_fst r) :: defs ls (mk_snd r); |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
183 |
val fixdefs = defs lhss fixpoint; |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
184 |
val define_all = fold_map (LocalTheory.define Thm.definitionK); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
185 |
val (fixdef_thms : (term * (string * thm)) list, lthy') = lthy |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
186 |
|> define_all (map (apfst fst) fixes ~~ fixdefs); |
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
187 |
fun pair_equalI (thm1, thm2) = @{thm Pair_equalI} OF [thm1, thm2]; |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
188 |
val tuple_fixdef_thm = foldr1 pair_equalI (map (snd o snd) fixdef_thms); |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
189 |
val P = Var (("P", 0), map Term.fastype_of lhss ---> HOLogic.boolT); |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
190 |
val predicate = lambda_tuple lhss (list_comb (P, lhss)); |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
191 |
val tuple_induct_thm = (def_cont_fix_ind OF [tuple_fixdef_thm, cont_thm]) |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
192 |
|> Drule.instantiate' [] [SOME (Thm.cterm_of thy predicate)] |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
193 |
|> LocalDefs.unfold lthy @{thms split_paired_all split_conv split_strict}; |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
194 |
val tuple_unfold_thm = (def_cont_fix_eq OF [tuple_fixdef_thm, cont_thm]) |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
195 |
|> LocalDefs.unfold lthy' @{thms split_conv}; |
23152 | 196 |
fun unfolds [] thm = [] |
197 |
| unfolds (n::[]) thm = [(n^"_unfold", thm)] |
|
198 |
| unfolds (n::ns) thm = let |
|
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
199 |
val thmL = thm RS @{thm Pair_eqD1}; |
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
200 |
val thmR = thm RS @{thm Pair_eqD2}; |
23152 | 201 |
in (n^"_unfold", thmL) :: unfolds ns thmR end; |
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
202 |
val unfold_thms = unfolds names tuple_unfold_thm; |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
203 |
fun mk_note (n, thm) = ((Binding.name n, []), [thm]); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
204 |
val (thmss, lthy'') = lthy' |
31177 | 205 |
|> fold_map (LocalTheory.note Thm.generatedK o mk_note) |
31095
b79d140f6d0b
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman
parents:
31023
diff
changeset
|
206 |
((all_names ^ "_induct", tuple_induct_thm) :: unfold_thms); |
23152 | 207 |
in |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
208 |
(lthy'', names, fixdef_thms, map snd unfold_thms) |
23152 | 209 |
end; |
210 |
||
211 |
(*************************************************************************) |
|
212 |
(*********** monadic notation and pattern matching compilation ***********) |
|
213 |
(*************************************************************************) |
|
214 |
||
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
215 |
structure FixrecMatchData = TheoryDataFun ( |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
216 |
type T = string Symtab.table; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
217 |
val empty = Symtab.empty; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
218 |
val copy = I; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
219 |
val extend = I; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
220 |
fun merge _ tabs : T = Symtab.merge (K true) tabs; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
221 |
); |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
222 |
|
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
223 |
(* associate match functions with pattern constants *) |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
224 |
fun add_matchers ms = FixrecMatchData.map (fold Symtab.update ms); |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
225 |
|
30157 | 226 |
fun taken_names (t : term) : bstring list = |
227 |
let |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
228 |
fun taken (Const(a,_), bs) = insert (op =) (Long_Name.base_name a) bs |
30157 | 229 |
| taken (Free(a,_) , bs) = insert (op =) a bs |
230 |
| taken (f $ u , bs) = taken (f, taken (u, bs)) |
|
231 |
| taken (Abs(a,_,t), bs) = taken (t, insert (op =) a bs) |
|
232 |
| taken (_ , bs) = bs; |
|
233 |
in |
|
234 |
taken (t, []) |
|
235 |
end; |
|
23152 | 236 |
|
237 |
(* builds a monadic term for matching a constructor pattern *) |
|
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
238 |
fun pre_build match_name pat rhs vs taken = |
23152 | 239 |
case pat of |
26045 | 240 |
Const(@{const_name Rep_CFun},_)$f$(v as Free(n,T)) => |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
241 |
pre_build match_name f rhs (v::vs) taken |
26045 | 242 |
| Const(@{const_name Rep_CFun},_)$f$x => |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
243 |
let val (rhs', v, taken') = pre_build match_name x rhs [] taken; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
244 |
in pre_build match_name f rhs' (v::vs) taken' end |
33401
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
245 |
| f$(v as Free(n,T)) => |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
246 |
pre_build match_name f rhs (v::vs) taken |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
247 |
| f$x => |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
248 |
let val (rhs', v, taken') = pre_build match_name x rhs [] taken; |
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
249 |
in pre_build match_name f rhs' (v::vs) taken' end |
23152 | 250 |
| Const(c,T) => |
251 |
let |
|
252 |
val n = Name.variant taken "v"; |
|
26045 | 253 |
fun result_type (Type(@{type_name "->"},[_,T])) (x::xs) = result_type T xs |
33401
fc43fa403a69
add fixrec support for HOL pair constructor patterns
huffman
parents:
33004
diff
changeset
|
254 |
| result_type (Type (@{type_name "fun"},[_,T])) (x::xs) = result_type T xs |
23152 | 255 |
| result_type T _ = T; |
256 |
val v = Free(n, result_type T vs); |
|
30912
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30485
diff
changeset
|
257 |
val m = Const(match_name c, matchT (T, fastype_of rhs)); |
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30485
diff
changeset
|
258 |
val k = big_lambdas vs rhs; |
23152 | 259 |
in |
30912
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30485
diff
changeset
|
260 |
(m`v`k, v, n::taken) |
23152 | 261 |
end |
262 |
| Free(n,_) => fixrec_err ("expected constructor, found free variable " ^ quote n) |
|
263 |
| _ => fixrec_err "pre_build: invalid pattern"; |
|
264 |
||
265 |
(* builds a monadic term for matching a function definition pattern *) |
|
266 |
(* returns (name, arity, matcher) *) |
|
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
267 |
fun building match_name pat rhs vs taken = |
23152 | 268 |
case pat of |
26045 | 269 |
Const(@{const_name Rep_CFun}, _)$f$(v as Free(n,T)) => |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
270 |
building match_name f rhs (v::vs) taken |
26045 | 271 |
| Const(@{const_name Rep_CFun}, _)$f$x => |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
272 |
let val (rhs', v, taken') = pre_build match_name x rhs [] taken; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
273 |
in building match_name f rhs' (v::vs) taken' end |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
274 |
| Free(_,_) => ((pat, length vs), big_lambdas vs rhs) |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
275 |
| Const(_,_) => ((pat, length vs), big_lambdas vs rhs) |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
276 |
| _ => fixrec_err ("function is not declared as constant in theory: " |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
277 |
^ ML_Syntax.print_term pat); |
23152 | 278 |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
279 |
fun strip_alls t = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
280 |
if Logic.is_all t then strip_alls (snd (Logic.dest_all t)) else t; |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
281 |
|
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
282 |
fun match_eq match_name eq = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
283 |
let |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
284 |
val (lhs,rhs) = dest_eqs (Logic.strip_imp_concl (strip_alls eq)); |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
285 |
in |
30157 | 286 |
building match_name lhs (mk_return rhs) [] (taken_names eq) |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
287 |
end; |
23152 | 288 |
|
289 |
(* returns the sum (using +++) of the terms in ms *) |
|
290 |
(* also applies "run" to the result! *) |
|
291 |
fun fatbar arity ms = |
|
292 |
let |
|
30132 | 293 |
fun LAM_Ts 0 t = ([], Term.fastype_of t) |
294 |
| LAM_Ts n (_ $ Abs(_,T,t)) = |
|
295 |
let val (Ts, U) = LAM_Ts (n-1) t in (T::Ts, U) end |
|
296 |
| LAM_Ts _ _ = fixrec_err "fatbar: internal error, not enough LAMs"; |
|
23152 | 297 |
fun unLAM 0 t = t |
298 |
| unLAM n (_$Abs(_,_,t)) = unLAM (n-1) t |
|
299 |
| unLAM _ _ = fixrec_err "fatbar: internal error, not enough LAMs"; |
|
30132 | 300 |
fun reLAM ([], U) t = t |
301 |
| reLAM (T::Ts, U) t = reLAM (Ts, T ->> U) (cabs_const(T,U)$Abs("",T,t)); |
|
302 |
val msum = foldr1 mk_mplus (map (unLAM arity) ms); |
|
303 |
val (Ts, U) = LAM_Ts arity (hd ms) |
|
23152 | 304 |
in |
30132 | 305 |
reLAM (rev Ts, dest_maybeT U) (mk_run msum) |
23152 | 306 |
end; |
307 |
||
308 |
(* this is the pattern-matching compiler function *) |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
309 |
fun compile_pats match_name eqs = |
23152 | 310 |
let |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
311 |
val (((n::names),(a::arities)),mats) = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
312 |
apfst ListPair.unzip (ListPair.unzip (map (match_eq match_name) eqs)); |
23152 | 313 |
val cname = if forall (fn x => n=x) names then n |
314 |
else fixrec_err "all equations in block must define the same function"; |
|
315 |
val arity = if forall (fn x => a=x) arities then a |
|
316 |
else fixrec_err "all equations in block must have the same arity"; |
|
317 |
val rhs = fatbar arity mats; |
|
318 |
in |
|
30132 | 319 |
mk_trp (cname === rhs) |
23152 | 320 |
end; |
321 |
||
322 |
(*************************************************************************) |
|
323 |
(********************** Proving associated theorems **********************) |
|
324 |
(*************************************************************************) |
|
325 |
||
326 |
(* proves a block of pattern matching equations as theorems, using unfold *) |
|
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
31740
diff
changeset
|
327 |
fun make_simps ctxt (unfold_thm, eqns : (Attrib.binding * term) list) = |
23152 | 328 |
let |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
329 |
val tacs = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
330 |
[rtac (unfold_thm RS @{thm ssubst_lhs}) 1, |
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
31740
diff
changeset
|
331 |
asm_simp_tac (simpset_of ctxt) 1]; |
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
31740
diff
changeset
|
332 |
fun prove_term t = Goal.prove ctxt [] [] t (K (EVERY tacs)); |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
333 |
fun prove_eqn (bind, eqn_t) = (bind, prove_term eqn_t); |
23152 | 334 |
in |
335 |
map prove_eqn eqns |
|
336 |
end; |
|
337 |
||
338 |
(*************************************************************************) |
|
339 |
(************************* Main fixrec function **************************) |
|
340 |
(*************************************************************************) |
|
341 |
||
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
342 |
local |
31738
7b9b9ba532ca
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
343 |
(* code adapted from HOL/Tools/primrec.ML *) |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
344 |
|
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
345 |
fun gen_fixrec |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
346 |
(set_group : bool) |
30485 | 347 |
prep_spec |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
348 |
(strict : bool) |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
349 |
raw_fixes |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
350 |
raw_spec |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
351 |
(lthy : local_theory) = |
23152 | 352 |
let |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
353 |
val (fixes : ((binding * typ) * mixfix) list, |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
354 |
spec : (Attrib.binding * term) list) = |
30485 | 355 |
fst (prep_spec raw_fixes raw_spec lthy); |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
356 |
val chead_of_spec = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
357 |
chead_of o fst o dest_eqs o Logic.strip_imp_concl o strip_alls o snd; |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
358 |
fun name_of (Free (n, _)) = n |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
359 |
| name_of t = fixrec_err ("unknown term"); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
360 |
val all_names = map (name_of o chead_of_spec) spec; |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
361 |
val names = distinct (op =) all_names; |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
362 |
fun block_of_name n = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
363 |
map_filter |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
364 |
(fn (m,eq) => if m = n then SOME eq else NONE) |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
365 |
(all_names ~~ spec); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
366 |
val blocks = map block_of_name names; |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
367 |
|
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
368 |
val matcher_tab = FixrecMatchData.get (ProofContext.theory_of lthy); |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
369 |
fun match_name c = |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
370 |
case Symtab.lookup matcher_tab c of SOME m => m |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
371 |
| NONE => fixrec_err ("unknown pattern constructor: " ^ c); |
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
372 |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
373 |
val matches = map (compile_pats match_name) (map (map snd) blocks); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
374 |
val spec' = map (pair Attrib.empty_binding) matches; |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
375 |
val (lthy', cnames, fixdef_thms, unfold_thms) = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
376 |
add_fixdefs fixes spec' lthy; |
23152 | 377 |
in |
378 |
if strict then let (* only prove simp rules if strict = true *) |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
379 |
val simps : (Attrib.binding * thm) list list = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
380 |
map (make_simps lthy') (unfold_thms ~~ blocks); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
381 |
fun mk_bind n : Attrib.binding = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
382 |
(Binding.name (n ^ "_simps"), |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
383 |
[Attrib.internal (K Simplifier.simp_add)]); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
384 |
val simps1 : (Attrib.binding * thm list) list = |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
385 |
map (fn (n,xs) => (mk_bind n, map snd xs)) (names ~~ simps); |
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
386 |
val simps2 : (Attrib.binding * thm list) list = |
32952 | 387 |
map (apsnd (fn thm => [thm])) (flat simps); |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
388 |
val (_, lthy'') = lthy' |
31177 | 389 |
|> fold_map (LocalTheory.note Thm.generatedK) (simps1 @ simps2); |
23152 | 390 |
in |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
391 |
lthy'' |
23152 | 392 |
end |
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
393 |
else lthy' |
23152 | 394 |
end; |
395 |
||
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
396 |
in |
23152 | 397 |
|
30485 | 398 |
val add_fixrec = gen_fixrec false Specification.check_spec; |
399 |
val add_fixrec_cmd = gen_fixrec true Specification.read_spec; |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
400 |
|
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
401 |
end; (* local *) |
23152 | 402 |
|
403 |
(*************************************************************************) |
|
404 |
(******************************** Fixpat *********************************) |
|
405 |
(*************************************************************************) |
|
406 |
||
407 |
fun fix_pat thy t = |
|
408 |
let |
|
409 |
val T = fastype_of t; |
|
410 |
val eq = mk_trp (HOLogic.eq_const T $ t $ Var (("x",0),T)); |
|
411 |
val cname = case chead_of t of Const(c,_) => c | _ => |
|
412 |
fixrec_err "function is not declared as constant in theory"; |
|
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
413 |
val unfold_thm = PureThy.get_thm thy (cname^"_unfold"); |
23152 | 414 |
val simp = Goal.prove_global thy [] [] eq |
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
31740
diff
changeset
|
415 |
(fn _ => EVERY [stac unfold_thm 1, simp_tac (global_simpset_of thy) 1]); |
23152 | 416 |
in simp end; |
417 |
||
418 |
fun gen_add_fixpat prep_term prep_attrib ((name, srcs), strings) thy = |
|
419 |
let |
|
420 |
val atts = map (prep_attrib thy) srcs; |
|
421 |
val ts = map (prep_term thy) strings; |
|
422 |
val simps = map (fix_pat thy) ts; |
|
423 |
in |
|
29585 | 424 |
(snd o PureThy.add_thmss [((name, simps), atts)]) thy |
23152 | 425 |
end; |
426 |
||
30485 | 427 |
val add_fixpat = gen_add_fixpat Sign.cert_term (K I); |
428 |
val add_fixpat_cmd = gen_add_fixpat Syntax.read_term_global Attrib.attribute; |
|
23152 | 429 |
|
430 |
||
431 |
(*************************************************************************) |
|
432 |
(******************************** Parsers ********************************) |
|
433 |
(*************************************************************************) |
|
434 |
||
435 |
local structure P = OuterParse and K = OuterKeyword in |
|
436 |
||
30485 | 437 |
val _ = OuterSyntax.local_theory "fixrec" "define recursive functions (HOLCF)" K.thy_decl |
438 |
((P.opt_keyword "permissive" >> not) -- P.fixes -- SpecParse.where_alt_specs |
|
439 |
>> (fn ((strict, fixes), specs) => add_fixrec_cmd strict fixes specs)); |
|
23152 | 440 |
|
30485 | 441 |
val _ = OuterSyntax.command "fixpat" "define rewrites for fixrec functions" K.thy_decl |
442 |
(SpecParse.specs >> (Toplevel.theory o add_fixpat_cmd)); |
|
30158
83c50c62cf23
fixrec package uses new-style syntax and local-theory interface
huffman
parents:
30157
diff
changeset
|
443 |
|
30485 | 444 |
end; |
23152 | 445 |
|
30131
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
446 |
val setup = FixrecMatchData.init; |
6be1be402ef0
use TheoryData to keep track of pattern match combinators
huffman
parents:
29585
diff
changeset
|
447 |
|
24867 | 448 |
end; |