488 fun get_cert thy (true, dtco) = get_cert_datatype thy dtco |
488 fun get_cert thy (true, dtco) = get_cert_datatype thy dtco |
489 | get_cert thy (false, dtco) = [TypecopyPackage.get_cert thy dtco]; |
489 | get_cert thy (false, dtco) = [TypecopyPackage.get_cert thy dtco]; |
490 |
490 |
491 local |
491 local |
492 val eq_def_sym = thm "eq_def" |> Thm.symmetric; |
492 val eq_def_sym = thm "eq_def" |> Thm.symmetric; |
493 val class_eq = "OperationalEquality.eq"; |
|
494 fun get_eq_thms thy tyco = case DatatypePackage.get_datatype thy tyco |
493 fun get_eq_thms thy tyco = case DatatypePackage.get_datatype thy tyco |
495 of SOME _ => get_eq_datatype thy tyco |
494 of SOME _ => get_eq_datatype thy tyco |
496 | NONE => [TypecopyPackage.get_eq thy tyco]; |
495 | NONE => [TypecopyPackage.get_eq thy tyco]; |
497 fun constrain_op_eq_thms thy thms = |
|
498 let |
|
499 fun add_eq (Const ("op =", ty)) = |
|
500 fold (insert (eq_fst (op =))) |
|
501 (Term.add_tvarsT ty []) |
|
502 | add_eq _ = |
|
503 I |
|
504 val eqs = fold (fold_aterms add_eq o Thm.prop_of) thms []; |
|
505 val instT = map (fn (v_i, sort) => |
|
506 (Thm.ctyp_of thy (TVar (v_i, sort)), |
|
507 Thm.ctyp_of thy (TVar (v_i, Sorts.inter_sort (Sign.classes_of thy) (sort, [class_eq]))))) eqs; |
|
508 in |
|
509 thms |
|
510 |> map (Thm.instantiate (instT, [])) |
|
511 end; |
|
512 in |
496 in |
513 fun get_eq thy tyco = |
497 fun get_eq thy tyco = |
514 get_eq_thms thy tyco |
498 get_eq_thms thy tyco |
515 |> maps ((#mk o #mk_rews o snd o MetaSimplifier.rep_ss o Simplifier.simpset_of) thy) |
499 |> maps ((#mk o #mk_rews o snd o MetaSimplifier.rep_ss o Simplifier.simpset_of) thy) |
516 |> constrain_op_eq_thms thy |
500 |> HOL.constrain_op_eq_thms thy |
517 |> map (Tactic.rewrite_rule [eq_def_sym]) |
501 |> map (Tactic.rewrite_rule [eq_def_sym]) |
518 end; |
502 end; |
519 |
503 |
520 type hook = (string * (bool * ((string * sort) list * (string * typ list) list))) list |
504 type hook = (string * (bool * ((string * sort) list * (string * typ list) list))) list |
521 -> theory -> theory; |
505 -> theory -> theory; |
613 end; |
597 end; |
614 |
598 |
615 |
599 |
616 (* operational equality *) |
600 (* operational equality *) |
617 |
601 |
618 local |
602 fun eq_hook specs = |
619 val class_eq = "OperationalEquality.eq"; |
|
620 in fun eq_hook specs = |
|
621 let |
603 let |
622 fun add_eq_thms (dtco, (_, (vs, cs))) thy = |
604 fun add_eq_thms (dtco, (_, (vs, cs))) thy = |
623 let |
605 let |
624 val thy_ref = Theory.self_ref thy; |
606 val thy_ref = Theory.self_ref thy; |
625 val ty = Type (dtco, map TFree vs) |> Logic.varifyT; |
607 val ty = Type (dtco, map TFree vs) |> Logic.varifyT; |
626 val c = CodegenConsts.norm thy ("OperationalEquality.eq", [ty]); |
608 val c = CodegenConsts.norm thy ("Code_Generator.eq", [ty]); |
627 val get_thms = (fn () => get_eq (Theory.deref thy_ref) dtco |> rev); |
609 val get_thms = (fn () => get_eq (Theory.deref thy_ref) dtco |> rev); |
628 in |
610 in |
629 CodegenData.add_funcl (c, CodegenData.lazy get_thms) thy |
611 CodegenData.add_funcl (c, CodegenData.lazy get_thms) thy |
630 end; |
612 end; |
631 in |
613 in |
632 prove_codetypes_arities (K (ClassPackage.intro_classes_tac [])) |
614 prove_codetypes_arities (K (ClassPackage.intro_classes_tac [])) |
633 (map (fn (tyco, (is_dt, _)) => (tyco, is_dt)) specs) |
615 (map (fn (tyco, (is_dt, _)) => (tyco, is_dt)) specs) |
634 [class_eq] ((K o K o pair) []) ((K o K) (fold add_eq_thms specs)) |
616 [HOLogic.class_eq] ((K o K o pair) []) ((K o K) (fold add_eq_thms specs)) |
635 end; |
617 end; |
636 end; (*local*) |
|
637 |
618 |
638 |
619 |
639 |
620 |
640 (** theory setup **) |
621 (** theory setup **) |
641 |
622 |