author | haftmann |
Fri, 29 Dec 2006 12:11:00 +0100 | |
changeset 21924 | fe474e69e603 |
parent 21894 | 1a0e32ccb8bb |
child 21936 | c7a7d3ab81d0 |
permissions | -rw-r--r-- |
18168 | 1 |
(* Title: Pure/Tools/class_package.ML |
2 |
ID: $Id$ |
|
3 |
Author: Florian Haftmann, TU Muenchen |
|
4 |
||
19468 | 5 |
Type classes derived from primitive axclasses and locales. |
18168 | 6 |
*) |
7 |
||
8 |
signature CLASS_PACKAGE = |
|
9 |
sig |
|
20964 | 10 |
val class: bstring -> class list -> Element.context Locale.element list -> theory -> |
11 |
string * Proof.context |
|
12 |
val class_i: bstring -> class list -> Element.context_i Locale.element list -> theory -> |
|
13 |
string * Proof.context |
|
20601 | 14 |
val instance_arity: ((bstring * string list) * string) list |
21924 | 15 |
-> ((bstring * Attrib.src list) * string) list |
18575 | 16 |
-> theory -> Proof.state |
20601 | 17 |
val instance_arity_i: ((bstring * sort list) * sort) list |
21924 | 18 |
-> ((bstring * attribute list) * term) list |
18575 | 19 |
-> theory -> Proof.state |
21924 | 20 |
val prove_instance_arity: tactic -> ((string * sort list) * sort) list |
21 |
-> ((bstring * attribute list) * term) list |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
22 |
-> theory -> theory |
19150 | 23 |
val instance_sort: string * string -> theory -> Proof.state |
24 |
val instance_sort_i: class * sort -> theory -> Proof.state |
|
25 |
val prove_instance_sort: tactic -> class * sort -> theory -> theory |
|
18168 | 26 |
|
18755 | 27 |
val certify_class: theory -> class -> class |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
28 |
val certify_sort: theory -> sort -> sort |
20385 | 29 |
val read_class: theory -> xstring -> class |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
30 |
val read_sort: theory -> string -> sort |
20175 | 31 |
val assume_arities_of_sort: theory -> ((string * sort list) * sort) list -> typ * sort -> bool |
32 |
val assume_arities_thy: theory -> ((string * sort list) * sort) list -> (theory -> 'a) -> 'a |
|
33 |
(*'a must not keep any reference to theory*) |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
34 |
|
21553 | 35 |
val add_def: class * thm -> theory -> theory |
36 |
val export_typ: theory -> class -> typ -> typ |
|
37 |
val export_def: theory -> class -> term -> term |
|
38 |
val export_thm: theory -> class -> thm -> thm |
|
39 |
||
18702 | 40 |
val print_classes: theory -> unit |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
41 |
val intro_classes_tac: thm list -> tactic |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
42 |
val default_intro_classes_tac: thm list -> tactic |
18168 | 43 |
end; |
44 |
||
20182
79c9ff40d760
tactic for prove_instance_arity now gets definition theorems as arguments
haftmann
parents:
20175
diff
changeset
|
45 |
structure ClassPackage : CLASS_PACKAGE = |
18168 | 46 |
struct |
47 |
||
48 |
||
20455 | 49 |
(** theory data **) |
18168 | 50 |
|
19456 | 51 |
datatype class_data = ClassData of { |
21924 | 52 |
locale: string, |
18575 | 53 |
var: string, |
20843 | 54 |
consts: (string * (string * typ)) list |
55 |
(*locale parameter ~> toplevel theory constant*), |
|
21553 | 56 |
propnames: string list, |
57 |
defs: thm list |
|
21924 | 58 |
}; |
18168 | 59 |
|
19456 | 60 |
fun rep_classdata (ClassData c) = c; |
61 |
||
18575 | 62 |
structure ClassData = TheoryDataFun ( |
18168 | 63 |
struct |
64 |
val name = "Pure/classes"; |
|
19966 | 65 |
type T = class_data Symtab.table; |
66 |
val empty = Symtab.empty; |
|
18168 | 67 |
val copy = I; |
68 |
val extend = I; |
|
21924 | 69 |
fun merge _ = Symtab.merge (K true); |
70 |
fun print _ _ = (); |
|
18168 | 71 |
end |
72 |
); |
|
73 |
||
18708 | 74 |
val _ = Context.add_setup ClassData.init; |
18575 | 75 |
|
19038 | 76 |
|
77 |
(* queries *) |
|
78 |
||
19966 | 79 |
val lookup_class_data = Option.map rep_classdata oo Symtab.lookup o ClassData.get; |
18168 | 80 |
|
19038 | 81 |
fun the_class_data thy class = |
18168 | 82 |
case lookup_class_data thy class |
20455 | 83 |
of NONE => error ("undeclared constructive class " ^ quote class) |
18168 | 84 |
| SOME data => data; |
85 |
||
20455 | 86 |
fun the_ancestry thy classes = |
18360 | 87 |
let |
20455 | 88 |
fun proj_class class = |
20843 | 89 |
if is_some (lookup_class_data thy class) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
90 |
then [class] |
20455 | 91 |
else (Sign.certify_sort thy o maps proj_class o Sign.super_classes thy) class; |
19038 | 92 |
fun ancestry class anc = |
93 |
anc |
|
20385 | 94 |
|> insert (op =) class |
20455 | 95 |
|> fold ancestry ((maps proj_class o Sign.super_classes thy) class); |
19038 | 96 |
in fold ancestry classes [] end; |
97 |
||
21924 | 98 |
val the_parm_map = #consts oo the_class_data; |
20455 | 99 |
|
21924 | 100 |
val the_propnames = #propnames oo the_class_data; |
20455 | 101 |
|
19038 | 102 |
fun subst_clsvar v ty_subst = |
103 |
map_type_tfree (fn u as (w, _) => |
|
104 |
if w = v then ty_subst else TFree u); |
|
105 |
||
21924 | 106 |
fun print_classes thy = |
107 |
let |
|
108 |
val algebra = Sign.classes_of thy; |
|
109 |
val arities = |
|
110 |
Symtab.empty |
|
111 |
|> Symtab.fold (fn (tyco, arities) => fold (fn (class, _) => |
|
112 |
Symtab.map_default (class, []) (insert (op =) tyco)) arities) |
|
113 |
((#arities o Sorts.rep_algebra) algebra); |
|
114 |
val the_arities = these o Symtab.lookup arities; |
|
115 |
fun mk_arity class tyco = |
|
116 |
let |
|
117 |
val Ss = Sorts.mg_domain algebra tyco [class]; |
|
118 |
in Sign.pretty_arity thy (tyco, Ss, [class]) end; |
|
119 |
fun mk_param (c, ty) = Pretty.str (Sign.extern_const thy c ^ " :: " |
|
120 |
^ setmp show_sorts false (Sign.string_of_typ thy o Type.strip_sorts) ty); |
|
121 |
fun mk_entry class = (Pretty.block o Pretty.fbreaks o map_filter I) [ |
|
122 |
(SOME o Pretty.str) ("class " ^ class ^ ":"), |
|
123 |
(SOME o Pretty.block) [Pretty.str "supersort: ", |
|
124 |
(Sign.pretty_sort thy o Sorts.certify_sort algebra o Sorts.super_classes algebra) class], |
|
125 |
Option.map (Pretty.str o prefix "locale: " o #locale) (lookup_class_data thy class), |
|
126 |
((fn [] => NONE | ps => (SOME o Pretty.block o Pretty.fbreaks) (Pretty.str "parameters:" :: ps)) o map mk_param |
|
127 |
o these o Option.map #params o try (AxClass.get_definition thy)) class, |
|
128 |
(SOME o Pretty.block o Pretty.breaks) [ |
|
129 |
Pretty.str "instances:", |
|
130 |
Pretty.list "" "" (map (mk_arity class) (the_arities class)) |
|
131 |
] |
|
132 |
] |
|
133 |
in |
|
134 |
(Pretty.writeln o Pretty.chunks o separate (Pretty.str "") o map mk_entry o Sorts.classes) algebra |
|
135 |
end; |
|
136 |
||
18168 | 137 |
|
19038 | 138 |
(* updaters *) |
139 |
||
21924 | 140 |
fun add_class_data (class, (locale, var, consts, propnames)) = |
19957 | 141 |
ClassData.map ( |
21924 | 142 |
Symtab.update_new (class, ClassData { |
143 |
locale = locale, |
|
19957 | 144 |
var = var, |
19966 | 145 |
consts = consts, |
21553 | 146 |
propnames = propnames, |
21924 | 147 |
defs = []}) |
19957 | 148 |
); |
19038 | 149 |
|
21553 | 150 |
fun add_def (class, thm) = |
21924 | 151 |
(ClassData.map o Symtab.map_entry class) |
152 |
(fn ClassData { locale, |
|
153 |
var, consts, propnames, defs } => ClassData { locale = locale, |
|
154 |
var = var, |
|
155 |
consts = consts, propnames = propnames, defs = thm :: defs }); |
|
19038 | 156 |
|
20106 | 157 |
|
21553 | 158 |
(* experimental class target *) |
159 |
||
160 |
fun export_typ thy loc = |
|
161 |
let |
|
162 |
val class = loc (*FIXME*); |
|
163 |
val (v, _) = AxClass.params_of_class thy class; |
|
164 |
in |
|
165 |
Term.map_type_tfree (fn var as (w, sort) => |
|
166 |
if w = v then TFree (w, Sorts.inter_sort (Sign.classes_of thy) |
|
167 |
(sort, [class])) else TFree var) |
|
168 |
end; |
|
169 |
||
170 |
fun export_def thy loc = |
|
171 |
let |
|
172 |
val class = loc (*FIXME*); |
|
21924 | 173 |
val data = the_class_data thy class; |
21553 | 174 |
val consts = #consts data; |
175 |
val v = #var data; |
|
176 |
val subst_typ = Term.map_type_tfree (fn var as (w, sort) => |
|
177 |
if w = v then TFree (w, Sorts.inter_sort (Sign.classes_of thy) |
|
178 |
(sort, [class])) else TFree var) |
|
179 |
fun subst (t as Free (v, _)) = (case AList.lookup (op =) consts v |
|
180 |
of SOME c_ty => Const c_ty |
|
181 |
| NONE => t) |
|
182 |
| subst t = t; |
|
183 |
in |
|
184 |
Term.map_aterms subst #> map_types subst_typ |
|
185 |
end; |
|
186 |
||
187 |
fun export_thm thy loc = |
|
188 |
let |
|
189 |
val class = loc (*FIXME*); |
|
21924 | 190 |
val thms = (#defs o the_class_data thy) class; |
21553 | 191 |
in |
21708 | 192 |
MetaSimplifier.rewrite_rule thms |
21553 | 193 |
end; |
194 |
||
195 |
||
20385 | 196 |
(* certification and reading *) |
19038 | 197 |
|
198 |
fun certify_class thy class = |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
199 |
(fn class => (the_class_data thy class; class)) (Sign.certify_class thy class); |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
200 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
201 |
fun certify_sort thy sort = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
202 |
map (fn class => (the_class_data thy class; class)) (Sign.certify_sort thy sort); |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
203 |
|
20385 | 204 |
fun read_class thy = |
19957 | 205 |
certify_class thy o Sign.intern_class thy; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
206 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
207 |
fun read_sort thy = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
208 |
certify_sort thy o Sign.read_sort thy; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
209 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
210 |
|
20455 | 211 |
|
212 |
(** contexts with arity assumptions **) |
|
20175 | 213 |
|
214 |
fun assume_arities_of_sort thy arities ty_sort = |
|
215 |
let |
|
216 |
val pp = Sign.pp thy; |
|
217 |
val algebra = Sign.classes_of thy |
|
218 |
|> fold (fn ((tyco, asorts), sort) => |
|
219 |
Sorts.add_arities pp (tyco, map (fn class => (class, asorts)) sort)) arities; |
|
220 |
in Sorts.of_sort algebra ty_sort end; |
|
221 |
||
222 |
fun assume_arities_thy thy arities f = |
|
223 |
let |
|
224 |
val thy_read = (fold (fn ((tyco, asorts), sort) |
|
225 |
=> Sign.primitive_arity (tyco, asorts, sort)) arities o Theory.copy) thy |
|
226 |
in f thy_read end; |
|
227 |
||
20455 | 228 |
|
229 |
||
230 |
(** tactics and methods **) |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
231 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
232 |
fun intro_classes_tac facts st = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
233 |
(ALLGOALS (Method.insert_tac facts THEN' |
19928 | 234 |
REPEAT_ALL_NEW (resolve_tac (AxClass.class_intros (Thm.theory_of_thm st)))) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
235 |
THEN Tactic.distinct_subgoals_tac) st; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
236 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
237 |
fun default_intro_classes_tac [] = intro_classes_tac [] |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
238 |
| default_intro_classes_tac _ = Tactical.no_tac; (*no error message!*) |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
239 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
240 |
fun default_tac rules ctxt facts = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
241 |
HEADGOAL (Method.some_rule_tac rules ctxt facts) ORELSE |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
242 |
default_intro_classes_tac facts; |
19038 | 243 |
|
19468 | 244 |
val _ = Context.add_setup (Method.add_methods |
245 |
[("intro_classes", Method.no_args (Method.METHOD intro_classes_tac), |
|
246 |
"back-chain introduction rules of classes"), |
|
247 |
("default", Method.thms_ctxt_args (Method.METHOD oo default_tac), |
|
248 |
"apply some intro/elim rule")]); |
|
249 |
||
19038 | 250 |
|
20455 | 251 |
|
252 |
(** axclass instances **) |
|
19246 | 253 |
|
254 |
local |
|
255 |
||
20175 | 256 |
fun gen_instance mk_prop add_thm after_qed insts thy = |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
257 |
let |
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
258 |
fun after_qed' results = |
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
259 |
ProofContext.theory ((fold o fold) add_thm results #> after_qed); |
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
260 |
in |
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
261 |
thy |
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
262 |
|> ProofContext.init |
21444 | 263 |
|> Proof.theorem_i NONE after_qed' ((map (fn t => [(t, [])]) o maps (mk_prop thy)) insts) |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
264 |
end; |
19246 | 265 |
|
266 |
in |
|
267 |
||
268 |
val axclass_instance_arity = |
|
19412 | 269 |
gen_instance (Logic.mk_arities oo Sign.read_arity) AxClass.add_arity; |
19246 | 270 |
val axclass_instance_arity_i = |
19412 | 271 |
gen_instance (Logic.mk_arities oo Sign.cert_arity) AxClass.add_arity; |
20182
79c9ff40d760
tactic for prove_instance_arity now gets definition theorems as arguments
haftmann
parents:
20175
diff
changeset
|
272 |
val axclass_instance_sort = |
21444 | 273 |
gen_instance (single oo (Logic.mk_classrel oo AxClass.read_classrel)) |
274 |
AxClass.add_classrel I o single; |
|
19246 | 275 |
|
276 |
end; |
|
277 |
||
278 |
||
20455 | 279 |
|
280 |
(** classes and instances **) |
|
19038 | 281 |
|
282 |
local |
|
283 |
||
19957 | 284 |
fun add_axclass_i (name, supsort) params axs thy = |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
285 |
let |
19395 | 286 |
val (c, thy') = thy |
19957 | 287 |
|> AxClass.define_class_i (name, supsort) params axs; |
19518 | 288 |
val {intro, axioms, ...} = AxClass.get_definition thy' c; |
19395 | 289 |
in ((c, (intro, axioms)), thy') end; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
290 |
|
20385 | 291 |
(*FIXME proper locale interface*) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
292 |
fun prove_interpretation_i (prfx, atts) expr insts tac thy = |
19038 | 293 |
let |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
294 |
fun ad_hoc_term (Const (c, ty)) = |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
295 |
let |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
296 |
val p = setmp show_types true (setmp show_sorts true (setmp print_mode [] (Sign.pretty_typ thy))) ty; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
297 |
val s = c ^ "::" ^ Pretty.output p; |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
298 |
in s end |
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
299 |
| ad_hoc_term t = |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
300 |
let |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
301 |
val p = setmp show_types true (setmp show_sorts true (setmp print_mode [] (Sign.pretty_term thy))) t; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
302 |
val s = Pretty.output p; |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
303 |
in s end; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
304 |
in |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
305 |
thy |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
306 |
|> Locale.interpretation I (prfx, atts) expr (map (Option.map ad_hoc_term) insts) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
307 |
|> Proof.global_terminal_proof (Method.Basic (fn _ => Method.SIMPLE_METHOD tac), NONE) |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
308 |
|> ProofContext.theory_of |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
309 |
end; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
310 |
|
19150 | 311 |
fun gen_class add_locale prep_class bname raw_supclasses raw_elems thy = |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
312 |
let |
20428 | 313 |
val (elems, exprs) = fold_rev (fn Locale.Elem e => apfst (cons e) |
314 |
| Locale.Expr e => apsnd (cons e)) |
|
315 |
raw_elems ([], []); |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
316 |
val supclasses = map (prep_class thy) raw_supclasses; |
19038 | 317 |
val supsort = |
318 |
supclasses |
|
19468 | 319 |
|> Sign.certify_sort thy |
21565 | 320 |
|> (fn [] => Sign.defaultS thy | S => S); (* FIXME Why syntax defaultS? *) |
20428 | 321 |
val expr_supclasses = Locale.Merge |
21924 | 322 |
(map (Locale.Locale o #locale o the_class_data thy) supclasses); |
323 |
val expr = Locale.Merge (map (Locale.Locale o #locale o the_class_data thy) supclasses |
|
20428 | 324 |
@ exprs); |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
325 |
val mapp_sup = AList.make |
19468 | 326 |
(the o AList.lookup (op =) ((flat o map (the_parm_map thy) o the_ancestry thy) supclasses)) |
20428 | 327 |
((map (fst o fst) o Locale.parameters_of_expr thy) expr_supclasses); |
19038 | 328 |
fun extract_tyvar_consts thy name_locale = |
329 |
let |
|
20175 | 330 |
fun extract_classvar ((c, ty), _) w = |
20428 | 331 |
(case Term.add_tfreesT ty [] |
20175 | 332 |
of [(v, _)] => (case w |
20385 | 333 |
of SOME u => if u = v then w else error ("Additonal type variable in type signature of constant " ^ quote c) |
20175 | 334 |
| NONE => SOME v) |
20385 | 335 |
| [] => error ("No type variable in type signature of constant " ^ quote c) |
336 |
| _ => error ("More than one type variable in type signature of constant " ^ quote c)); |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
337 |
val consts1 = |
19038 | 338 |
Locale.parameters_of thy name_locale |
21805 | 339 |
|> map (apsnd (TheoryTarget.fork_mixfix false true #> fst)) |
20175 | 340 |
val SOME v = fold extract_classvar consts1 NONE; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
341 |
val consts2 = map ((apfst o apsnd) (subst_clsvar v (TFree (v, [])))) consts1; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
342 |
in (v, chop (length mapp_sup) consts2) end; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
343 |
fun add_consts v raw_cs_sup raw_cs_this thy = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
344 |
let |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
345 |
fun add_global_const ((c, ty), syn) thy = |
20265 | 346 |
((c, (Sign.full_name thy c, ty)), |
347 |
thy |
|
20703 | 348 |
|> Sign.add_consts_authentic [(c, ty |> subst_clsvar v (TFree (v, Sign.defaultS thy)), syn)]); |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
349 |
in |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
350 |
thy |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
351 |
|> fold_map add_global_const raw_cs_this |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
352 |
end; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
353 |
fun extract_assumes thy name_locale cs_mapp = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
354 |
let |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
355 |
val subst_assume = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
356 |
map_aterms (fn Free (c, ty) => Const ((fst o the o AList.lookup (op =) cs_mapp) c, ty) |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
357 |
| t => t) |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
358 |
fun prep_asm ((name, atts), ts) = |
19957 | 359 |
((NameSpace.base name, map (Attrib.attribute thy) atts), map subst_assume ts) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
360 |
in |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
361 |
(map prep_asm o Locale.local_asms_of thy) name_locale |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
362 |
end; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
363 |
fun add_global_constraint v class (_, (c, ty)) thy = |
19038 | 364 |
thy |
19136 | 365 |
|> Sign.add_const_constraint_i (c, SOME (subst_clsvar v (TFree (v, [class])) ty)); |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
366 |
fun mk_const thy class v (c, ty) = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
367 |
Const (c, subst_clsvar v (TFree (v, [class])) ty); |
19038 | 368 |
in |
369 |
thy |
|
20428 | 370 |
|> add_locale bname expr elems |
20964 | 371 |
|-> (fn name_locale => ProofContext.theory |
372 |
(`(fn thy => extract_tyvar_consts thy name_locale) |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
373 |
#-> (fn (v, (raw_cs_sup, raw_cs_this)) => |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
374 |
add_consts v raw_cs_sup raw_cs_this |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
375 |
#-> (fn mapp_this => |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
376 |
`(fn thy => extract_assumes thy name_locale (mapp_sup @ mapp_this)) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
377 |
#-> (fn loc_axioms => |
19957 | 378 |
add_axclass_i (bname, supsort) (map (fst o snd) mapp_this) loc_axioms |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
379 |
#-> (fn (name_axclass, (_, ax_axioms)) => |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
380 |
fold (add_global_constraint v name_axclass) mapp_this |
21924 | 381 |
#> add_class_data (name_locale, (name_locale, v, mapp_this, |
21463
42dd50268c8b
completed class parameter handling in axclass.ML
haftmann
parents:
21444
diff
changeset
|
382 |
map (fst o fst) loc_axioms)) |
21751 | 383 |
#> prove_interpretation_i (Logic.const_of_class bname, []) |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
384 |
(Locale.Locale name_locale) (map (SOME o mk_const thy name_axclass v) (map snd (mapp_sup @ mapp_this))) |
19929 | 385 |
((ALLGOALS o ProofContext.fact_tac) ax_axioms) |
20964 | 386 |
))))) #> pair name_locale) |
19038 | 387 |
end; |
388 |
||
389 |
in |
|
390 |
||
20385 | 391 |
val class = gen_class (Locale.add_locale false) read_class; |
19928 | 392 |
val class_i = gen_class (Locale.add_locale_i false) certify_class; |
19038 | 393 |
|
20455 | 394 |
end; (*local*) |
19038 | 395 |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
396 |
local |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
397 |
|
20175 | 398 |
fun gen_read_def thy prep_att read_def ((raw_name, raw_atts), raw_t) = |
19038 | 399 |
let |
19957 | 400 |
val (_, t) = read_def thy (raw_name, raw_t); |
401 |
val ((c, ty), _) = Sign.cert_def (Sign.pp thy) t; |
|
402 |
val atts = map (prep_att thy) raw_atts; |
|
20175 | 403 |
val insts = (Consts.typargs (Sign.consts_of thy) (c, ty)) |
19957 | 404 |
val name = case raw_name |
20385 | 405 |
of "" => NONE |
406 |
| _ => SOME raw_name; |
|
20175 | 407 |
in (c, (insts, ((name, t), atts))) end; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
408 |
|
19957 | 409 |
fun read_def thy = gen_read_def thy Attrib.attribute read_axm; |
410 |
fun read_def_i thy = gen_read_def thy (K I) (K I); |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
411 |
|
21924 | 412 |
fun gen_instance_arity prep_arity prep_att read_def do_proof raw_arities raw_defs theory = |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
413 |
let |
20175 | 414 |
fun prep_arity' ((tyco, asorts), sort) = prep_arity theory (tyco, asorts, sort); |
415 |
val arities = map prep_arity' raw_arities; |
|
416 |
val arities_pair = map (fn (tyco, asorts, sort) => ((tyco, asorts), sort)) arities; |
|
417 |
val _ = if null arities then error "at least one arity must be given" else (); |
|
418 |
val _ = case (duplicates (op =) o map #1) arities |
|
419 |
of [] => () |
|
420 |
| dupl_tycos => error ("type constructors occur more than once in arities: " |
|
421 |
^ (commas o map quote) dupl_tycos); |
|
422 |
fun get_consts_class tyco ty class = |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
423 |
let |
21463
42dd50268c8b
completed class parameter handling in axclass.ML
haftmann
parents:
21444
diff
changeset
|
424 |
val (_, cs) = AxClass.params_of_class theory class; |
42dd50268c8b
completed class parameter handling in axclass.ML
haftmann
parents:
21444
diff
changeset
|
425 |
val subst_ty = map_type_tfree (K ty); |
19957 | 426 |
in |
21894 | 427 |
map (fn (c, ty) => (c, ((tyco, class), subst_ty ty))) cs |
19957 | 428 |
end; |
20175 | 429 |
fun get_consts_sort (tyco, asorts, sort) = |
19957 | 430 |
let |
20192
956cd30ef3be
renamed Name.give_names to Name.names and moved Name.alphanum to Symbol.alphanum
haftmann
parents:
20191
diff
changeset
|
431 |
val ty = Type (tyco, map (fn (v, sort) => TVar ((v, 0), sort)) (Name.names Name.context "'a" asorts)) |
20175 | 432 |
in maps (get_consts_class tyco ty) (the_ancestry theory sort) end; |
433 |
val cs = maps get_consts_sort arities; |
|
20385 | 434 |
fun mk_typnorm thy (ty, ty_sc) = |
435 |
case try (Sign.typ_match thy (Logic.varifyT ty_sc, ty)) Vartab.empty |
|
436 |
of SOME env => SOME (Logic.varifyT #> Envir.typ_subst_TVars env #> Logic.unvarifyT) |
|
437 |
| NONE => NONE; |
|
20175 | 438 |
fun read_defs defs cs thy_read = |
439 |
let |
|
19957 | 440 |
fun read raw_def cs = |
441 |
let |
|
20385 | 442 |
val (c, (inst, ((name_opt, t), atts))) = read_def thy_read raw_def; |
443 |
val ty = Consts.instance (Sign.consts_of thy_read) (c, inst); |
|
20175 | 444 |
val ((tyco, class), ty') = case AList.lookup (op =) cs c |
19957 | 445 |
of NONE => error ("superfluous definition for constant " ^ quote c) |
19966 | 446 |
| SOME class_ty => class_ty; |
20385 | 447 |
val name = case name_opt |
20628 | 448 |
of NONE => Thm.def_name (Logic.name_arity (tyco, [], c)) |
20385 | 449 |
| SOME name => name; |
450 |
val t' = case mk_typnorm thy_read (ty', ty) |
|
19966 | 451 |
of NONE => error ("superfluous definition for constant " ^ |
452 |
quote c ^ "::" ^ Sign.string_of_typ thy_read ty) |
|
20548
8ef25fe585a8
renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents:
20465
diff
changeset
|
453 |
| SOME norm => map_types norm t |
20175 | 454 |
in (((class, tyco), ((name, t'), atts)), AList.delete (op =) c cs) end; |
19957 | 455 |
in fold_map read defs cs end; |
20175 | 456 |
val (defs, _) = assume_arities_thy theory arities_pair (read_defs raw_defs cs); |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
457 |
fun get_remove_contraint c thy = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
458 |
let |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
459 |
val ty = Sign.the_const_constraint thy c; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
460 |
in |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
461 |
thy |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
462 |
|> Sign.add_const_constraint_i (c, NONE) |
20385 | 463 |
|> pair (c, Logic.unvarifyT ty) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
464 |
end; |
19966 | 465 |
fun add_defs defs thy = |
466 |
thy |
|
467 |
|> PureThy.add_defs_i true (map snd defs) |
|
468 |
|-> (fn thms => pair (map fst defs ~~ thms)); |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
469 |
fun after_qed cs thy = |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
470 |
thy |
19412 | 471 |
|> fold Sign.add_const_constraint_i (map (apsnd SOME) cs); |
19038 | 472 |
in |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
473 |
theory |
20385 | 474 |
|> fold_map get_remove_contraint (map fst cs |> distinct (op =)) |
19966 | 475 |
||>> add_defs defs |
21924 | 476 |
|-> (fn (cs, def_thms) => do_proof (after_qed cs) arities) |
19038 | 477 |
end; |
478 |
||
19957 | 479 |
fun instance_arity' do_proof = gen_instance_arity Sign.read_arity Attrib.attribute |
480 |
read_def do_proof; |
|
481 |
fun instance_arity_i' do_proof = gen_instance_arity Sign.cert_arity (K I) |
|
482 |
read_def_i do_proof; |
|
21924 | 483 |
fun tactic_proof tac after_qed arities = |
484 |
fold (fn arity => AxClass.prove_arity arity tac) arities |
|
20175 | 485 |
#> after_qed; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
486 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
487 |
in |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
488 |
|
21924 | 489 |
val instance_arity = instance_arity' axclass_instance_arity_i; |
490 |
val instance_arity_i = instance_arity_i' axclass_instance_arity_i; |
|
19150 | 491 |
val prove_instance_arity = instance_arity_i' o tactic_proof; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
492 |
|
20455 | 493 |
end; (*local*) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
494 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
495 |
local |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
496 |
|
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
497 |
fun prove_interpretation_in tac after_qed (name, expr) thy = |
19136 | 498 |
thy |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
499 |
|> Locale.interpretation_in_locale (ProofContext.theory after_qed) (name, expr) |
19136 | 500 |
|> Proof.global_terminal_proof (Method.Basic (fn _ => Method.SIMPLE_METHOD tac), NONE) |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
501 |
|> ProofContext.theory_of; |
19038 | 502 |
|
20385 | 503 |
(*FIXME very ad-hoc, needs proper locale interface*) |
19150 | 504 |
fun gen_instance_sort prep_class prep_sort do_proof (raw_class, raw_sort) theory = |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
505 |
let |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
506 |
val class = prep_class theory raw_class; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
507 |
val sort = prep_sort theory raw_sort; |
21924 | 508 |
val loc_name = (#locale o the_class_data theory) class; |
19468 | 509 |
val loc_expr = |
21924 | 510 |
(Locale.Merge o map (Locale.Locale o #locale o the_class_data theory)) sort; |
19966 | 511 |
val const_names = (map (NameSpace.base o fst o snd) |
21924 | 512 |
o maps (#consts o the_class_data theory) |
19966 | 513 |
o the_ancestry theory) [class]; |
20106 | 514 |
fun get_thms thy = |
515 |
the_ancestry thy sort |
|
516 |
|> AList.make (the_propnames thy) |
|
21751 | 517 |
|> map (apsnd (map (NameSpace.append (Logic.const_of_class loc_name)))) |
20106 | 518 |
|> map_filter (fn (superclass, thm_names) => |
519 |
case map_filter (try (PureThy.get_thm thy o Name)) thm_names |
|
520 |
of [] => NONE |
|
521 |
| thms => SOME (superclass, thms)); |
|
522 |
fun after_qed thy = |
|
523 |
thy |
|
524 |
|> `get_thms |
|
525 |
|-> fold (fn (supclass, thms) => I |
|
526 |
AxClass.prove_classrel (class, supclass) |
|
527 |
(ALLGOALS (K (intro_classes_tac [])) THEN |
|
528 |
(ALLGOALS o ProofContext.fact_tac) thms)) |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
529 |
in |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
530 |
theory |
19136 | 531 |
|> do_proof after_qed (loc_name, loc_expr) |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
532 |
end; |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
533 |
|
20385 | 534 |
fun instance_sort' do_proof = gen_instance_sort read_class read_sort do_proof; |
19150 | 535 |
fun instance_sort_i' do_proof = gen_instance_sort certify_class certify_sort do_proof; |
20368
2461a0485623
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20353
diff
changeset
|
536 |
val setup_proof = Locale.interpretation_in_locale o ProofContext.theory; |
19136 | 537 |
val tactic_proof = prove_interpretation_in; |
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
538 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
539 |
in |
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
540 |
|
19150 | 541 |
val instance_sort = instance_sort' setup_proof; |
542 |
val instance_sort_i = instance_sort_i' setup_proof; |
|
543 |
val prove_instance_sort = instance_sort_i' o tactic_proof; |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
544 |
|
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
545 |
end; (* local *) |
19038 | 546 |
|
19957 | 547 |
|
20455 | 548 |
(** toplevel interface **) |
18515 | 549 |
|
550 |
local |
|
551 |
||
552 |
structure P = OuterParse |
|
553 |
and K = OuterKeyword |
|
554 |
||
555 |
in |
|
556 |
||
20385 | 557 |
val (classK, instanceK, print_classesK) = ("class", "instance", "print_classes") |
18515 | 558 |
|
20385 | 559 |
fun wrap_add_instance_sort (class, sort) thy = |
560 |
(if forall (is_some o lookup_class_data thy) (Sign.read_sort thy sort) |
|
21094 | 561 |
andalso (is_some o lookup_class_data thy) (Sign.intern_class thy class) |
20385 | 562 |
then instance_sort else axclass_instance_sort) (class, sort) thy; |
19136 | 563 |
|
20385 | 564 |
val class_subP = P.name -- Scan.repeat (P.$$$ "+" |-- P.name) >> (op ::); |
20428 | 565 |
val class_bodyP = P.!!! (Scan.repeat1 P.locale_element); |
20385 | 566 |
|
20601 | 567 |
val parse_arity = |
568 |
(P.xname --| P.$$$ "::" -- P.!!! P.arity) |
|
19136 | 569 |
>> (fn (tyco, (asorts, sort)) => ((tyco, asorts), sort)); |
18911 | 570 |
|
18515 | 571 |
val classP = |
20385 | 572 |
OuterSyntax.command classK "define operational type class" K.thy_decl ( |
18849
05a16861d3a5
added three times overloaded Isar instance command
haftmann
parents:
18829
diff
changeset
|
573 |
P.name --| P.$$$ "=" |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
574 |
-- ( |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
575 |
class_subP --| P.$$$ "+" -- class_bodyP |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
576 |
|| class_subP >> rpair [] |
20964 | 577 |
|| class_bodyP >> pair []) |
578 |
-- P.opt_begin |
|
579 |
>> (fn ((bname, (supclasses, elems)), begin) => |
|
21805 | 580 |
Toplevel.begin_local_theory begin |
581 |
(class bname supclasses elems #-> TheoryTarget.begin true))); |
|
18515 | 582 |
|
18575 | 583 |
val instanceP = |
18849
05a16861d3a5
added three times overloaded Isar instance command
haftmann
parents:
18829
diff
changeset
|
584 |
OuterSyntax.command instanceK "prove type arity or subclass relation" K.thy_goal (( |
20385 | 585 |
P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) >> wrap_add_instance_sort |
21924 | 586 |
|| P.and_list1 parse_arity -- Scan.repeat (P.opt_thm_name ":" -- P.prop) |
587 |
>> (fn ([((tyco, asorts), sort)], []) => axclass_instance_arity I [(tyco, asorts, sort)] |
|
588 |
| (arities, defs) => instance_arity arities defs) |
|
18849
05a16861d3a5
added three times overloaded Isar instance command
haftmann
parents:
18829
diff
changeset
|
589 |
) >> (Toplevel.print oo Toplevel.theory_to_proof)); |
18575 | 590 |
|
20385 | 591 |
val print_classesP = |
592 |
OuterSyntax.improper_command print_classesK "print classes of this theory" K.diag |
|
593 |
(Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory |
|
594 |
o Toplevel.keep (print_classes o Toplevel.theory_of))); |
|
595 |
||
596 |
val _ = OuterSyntax.add_parsers [classP, instanceP, print_classesP]; |
|
19110
4bda27adcd2e
moved intro_classes from AxClass to ClassPackage
haftmann
parents:
19102
diff
changeset
|
597 |
|
20455 | 598 |
end; (*local*) |
18515 | 599 |
|
20455 | 600 |
end; |