src/HOL/Library/Eval.thy
changeset 25864 11f531354852
parent 25763 474f8ba9dfa9
child 25919 8b1c0d434824
equal deleted inserted replaced
25863:5b4a8b1d0f88 25864:11f531354852
    97       val eq = Syntax.check_term lthy (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)))
    97       val eq = Syntax.check_term lthy (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)))
    98     in lthy |> Specification.definition (NONE, (("", []), eq)) end;
    98     in lthy |> Specification.definition (NONE, (("", []), eq)) end;
    99   fun interpretator tyco thy =
    99   fun interpretator tyco thy =
   100     let
   100     let
   101       val sorts = replicate (Sign.arity_number thy tyco) @{sort typ_of};
   101       val sorts = replicate (Sign.arity_number thy tyco) @{sort typ_of};
   102       val ty = Type (tyco, map TFree (Name.names Name.context "'a" sorts));
   102       val vs = Name.names Name.context "'a" sorts;
       
   103       val ty = Type (tyco, map TFree vs);
   103     in
   104     in
   104       thy
   105       thy
   105       |> TheoryTarget.instantiation ([tyco], sorts, @{sort typ_of})
   106       |> TheoryTarget.instantiation ([tyco], vs, @{sort typ_of})
   106       |> define_typ_of ty
   107       |> define_typ_of ty
   107       |> snd
   108       |> snd
   108       |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
   109       |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
   109       |> LocalTheory.exit
   110       |> LocalTheory.exit
   110       |> ProofContext.theory_of
   111       |> ProofContext.theory_of
   263       val vs = map fst vs_proto ~~ sorts;
   264       val vs = map fst vs_proto ~~ sorts;
   264       val css = map (prep_dtyp thy vs) tycos;
   265       val css = map (prep_dtyp thy vs) tycos;
   265       val defs = map (mk_terms_of_defs vs) css;
   266       val defs = map (mk_terms_of_defs vs) css;
   266     in if forall (fn tyco => can (Sign.arity_sorts thy tyco) @{sort term_of}) dep_tycos
   267     in if forall (fn tyco => can (Sign.arity_sorts thy tyco) @{sort term_of}) dep_tycos
   267         andalso not (tycos = [@{type_name typ}])
   268         andalso not (tycos = [@{type_name typ}])
   268       then SOME (sorts, defs)
   269       then SOME (vs, defs)
   269       else NONE
   270       else NONE
   270     end;
   271     end;
   271   fun prep' ctxt proto_eqs =
   272   fun prep' ctxt proto_eqs =
   272     let
   273     let
   273       val eqs as eq :: _ = map (Syntax.check_term ctxt) proto_eqs;
   274       val eqs as eq :: _ = map (Syntax.check_term ctxt) proto_eqs;
   277   fun primrec primrecs ctxt =
   278   fun primrec primrecs ctxt =
   278     let
   279     let
   279       val (fixes, eqnss) = split_list (map (prep' ctxt) primrecs);
   280       val (fixes, eqnss) = split_list (map (prep' ctxt) primrecs);
   280     in PrimrecPackage.add_primrec fixes (flat eqnss) ctxt end;
   281     in PrimrecPackage.add_primrec fixes (flat eqnss) ctxt end;
   281   fun interpretator tycos thy = case prep thy tycos
   282   fun interpretator tycos thy = case prep thy tycos
   282    of SOME (sorts, defs) =>
   283    of SOME (vs, defs) =>
   283       thy
   284       thy
   284       |> TheoryTarget.instantiation (tycos, sorts, @{sort term_of})
   285       |> TheoryTarget.instantiation (tycos, vs, @{sort term_of})
   285       |> primrec defs
   286       |> primrec defs
   286       |> snd
   287       |> snd
   287       |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
   288       |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
   288       |> LocalTheory.exit
   289       |> LocalTheory.exit
   289       |> ProofContext.theory_of
   290       |> ProofContext.theory_of