216 datatype class_data = ClassData of { |
216 datatype class_data = ClassData of { |
217 locale: string, |
217 locale: string, |
218 consts: (string * string) list |
218 consts: (string * string) list |
219 (*locale parameter ~> toplevel theory constant*), |
219 (*locale parameter ~> toplevel theory constant*), |
220 propnames: string list, |
220 propnames: string list, |
|
221 (*for ad-hoc instance in*) |
221 defs: thm list |
222 defs: thm list |
222 (*for experimental class target*) |
223 (*for experimental class target*) |
223 }; |
224 }; |
224 |
225 |
225 fun rep_classdata (ClassData c) = c; |
226 fun rep_classdata (ClassData c) = c; |
305 #> fold (curry Graph.add_edge class) superclasses |
306 #> fold (curry Graph.add_edge class) superclasses |
306 ); |
307 ); |
307 |
308 |
308 fun add_def (class, thm) = |
309 fun add_def (class, thm) = |
309 (ClassData.map o Graph.map_node class) |
310 (ClassData.map o Graph.map_node class) |
310 (fn ClassData { locale, |
311 (fn ClassData { locale, consts, propnames, defs } => ClassData { locale = locale, |
311 consts, propnames, defs } => ClassData { locale = locale, |
|
312 consts = consts, propnames = propnames, defs = thm :: defs }); |
312 consts = consts, propnames = propnames, defs = thm :: defs }); |
313 |
313 |
314 |
314 |
315 (* tactics and methods *) |
315 (* tactics and methods *) |
316 |
316 |
317 fun intro_classes_tac facts st = |
317 fun intro_classes_tac facts st = |
318 (ALLGOALS (Method.insert_tac facts THEN' |
318 let |
319 REPEAT_ALL_NEW (resolve_tac (AxClass.class_intros (Thm.theory_of_thm st)))) |
319 val thy = Thm.theory_of_thm st; |
320 THEN Tactic.distinct_subgoals_tac) st; |
320 val ctxt = ProofContext.init thy; |
|
321 val intro_classes_tac = ALLGOALS |
|
322 (Method.insert_tac facts THEN' REPEAT_ALL_NEW (resolve_tac (AxClass.class_intros thy))) |
|
323 THEN Tactic.distinct_subgoals_tac; |
|
324 val intro_locales_tac = Locale.intro_locales_tac true ctxt facts; |
|
325 in |
|
326 (intro_classes_tac THEN TRY intro_locales_tac) st |
|
327 end; |
321 |
328 |
322 fun default_intro_classes_tac [] = intro_classes_tac [] |
329 fun default_intro_classes_tac [] = intro_classes_tac [] |
323 | default_intro_classes_tac _ = Tactical.no_tac; (*no error message!*) |
330 | default_intro_classes_tac _ = Tactical.no_tac; (*no error message!*) |
324 |
331 |
325 fun default_tac rules ctxt facts = |
332 fun default_tac rules ctxt facts = |
449 | subst t = t; |
456 | subst t = t; |
450 fun prep_asm ((name, atts), ts) = |
457 fun prep_asm ((name, atts), ts) = |
451 (*FIXME*) |
458 (*FIXME*) |
452 ((NameSpace.base name, map (Attrib.attribute thy) atts), (map o map_aterms) subst ts); |
459 ((NameSpace.base name, map (Attrib.attribute thy) atts), (map o map_aterms) subst ts); |
453 in |
460 in |
454 Locale.local_asms_of thy name_locale |
461 Locale.global_asms_of thy name_locale |
455 |> map prep_asm |
462 |> map prep_asm |
456 end; |
463 end; |
457 fun extract_axiom_names thy name_locale = |
464 fun extract_axiom_names thy name_locale = |
458 name_locale |
465 name_locale |
459 |> Locale.local_asms_of thy |
466 |> Locale.global_asms_of thy |
460 |> map (NameSpace.base o fst o fst) (*FIXME*) |
467 |> map (NameSpace.base o fst o fst) (*FIXME*) |
461 fun mk_const thy class (c, ty) = |
468 fun mk_const thy class (c, ty) = |
462 Const (c, Term.map_type_tfree (fn (v, _) => TFree (v, [class])) ty); |
469 Const (c, Term.map_type_tfree (fn (v, _) => TFree (v, [class])) ty); |
|
470 (*fun note_thms class name_locale cs thy = |
|
471 let (*FIXME just an ad-hoc feature*) |
|
472 val names = fold (fn Element.Assumes xs => fold (cons o fst o fst) xs |
|
473 | Element.Notes (name, _) => cons name |
|
474 | _ => I) elems [] |
|
475 val const_names = cs; |
|
476 val path = NameSpace.base class; |
|
477 val prefix = NameSpace.implode [class ^ "_class", space_implode "_" const_names]; |
|
478 fun note_thm name thy = |
|
479 case try (PureThy.get_thm thy) (Name (NameSpace.append prefix name)) |
|
480 of SOME thm => |
|
481 thy |
|
482 |> PureThy.note_thmss_qualified "" path [((name, []), [([thm], [])])] |
|
483 |> snd |
|
484 | NONE => error name; |
|
485 in |
|
486 thy |
|
487 |> fold note_thm names |
|
488 end;*) |
463 in |
489 in |
464 thy |
490 thy |
465 |> add_locale bname supexpr elems |
491 |> add_locale bname supexpr elems |
466 |-> (fn name_locale => ProofContext.theory_result ( |
492 |-> (fn name_locale => ProofContext.theory_result ( |
467 tap (fn thy => check_locale thy name_locale) |
493 tap (fn thy => check_locale thy name_locale) |
472 `(fn thy => extract_axiom_names thy name_locale) |
498 `(fn thy => extract_axiom_names thy name_locale) |
473 #-> (fn axiom_names => |
499 #-> (fn axiom_names => |
474 add_class_data ((name_axclass, supclasses), |
500 add_class_data ((name_axclass, supclasses), |
475 (name_locale, map (fst o fst) params ~~ map fst consts, axiom_names)) |
501 (name_locale, map (fst o fst) params ~~ map fst consts, axiom_names)) |
476 #> prove_interpretation (Logic.const_of_class bname, []) |
502 #> prove_interpretation (Logic.const_of_class bname, []) |
477 (Locale.Locale name_locale) (map (SOME o mk_const thy name_axclass) (map snd supconsts @ consts)) |
503 (Locale.Locale name_locale) (map (SOME o mk_const thy name_axclass) (map snd supconsts @ consts)) |
478 ((ALLGOALS o ProofContext.fact_tac) ax_axioms) |
504 ((ALLGOALS o ProofContext.fact_tac) ax_axioms) |
|
505 (*#> note_thms name_axclass name_locale (map fst supconsts @ map (fst o fst) params)*) |
479 #> pair name_axclass |
506 #> pair name_axclass |
480 ))))) |
507 ))))) |
481 end; |
508 end; |
482 |
509 |
483 in |
510 in |
484 |
511 |
485 val class_e = gen_class (Locale.add_locale false) read_class; |
512 val class_e = gen_class (Locale.add_locale true) read_class; |
486 val class = gen_class (Locale.add_locale_i false) certify_class; |
513 val class = gen_class (Locale.add_locale_i true) certify_class; |
487 |
514 |
488 end; (*local*) |
515 end; (*local*) |
489 |
516 |
490 local |
517 local |
491 |
518 |