src/HOL/Tools/code_evaluation.ML
changeset 40726 16dcfedc4eb7
parent 39567 5ee997fbe5cc
child 41184 5c6f44d22f51
equal deleted inserted replaced
40717:88f2955a111e 40726:16dcfedc4eb7
    52   in if need_inst then add_term_of tyco raw_vs thy else thy end;
    52   in if need_inst then add_term_of tyco raw_vs thy else thy end;
    53 
    53 
    54 
    54 
    55 (* code equations for datatypes *)
    55 (* code equations for datatypes *)
    56 
    56 
    57 fun mk_term_of_eq thy ty (c, tys) =
    57 fun mk_term_of_eq thy ty (c, (_, tys)) =
    58   let
    58   let
    59     val t = list_comb (Const (c, tys ---> ty),
    59     val t = list_comb (Const (c, tys ---> ty),
    60       map Free (Name.names Name.context "a" tys));
    60       map Free (Name.names Name.context "a" tys));
    61     val (arg, rhs) =
    61     val (arg, rhs) =
    62       pairself (Thm.cterm_of thy o map_types Logic.unvarifyT_global o Logic.varify_global)
    62       pairself (Thm.cterm_of thy o map_types Logic.unvarifyT_global o Logic.varify_global)
    72   let
    72   let
    73     val algebra = Sign.classes_of thy;
    73     val algebra = Sign.classes_of thy;
    74     val vs = map (fn (v, sort) =>
    74     val vs = map (fn (v, sort) =>
    75       (v, curry (Sorts.inter_sort algebra) @{sort typerep} sort)) raw_vs;
    75       (v, curry (Sorts.inter_sort algebra) @{sort typerep} sort)) raw_vs;
    76     val ty = Type (tyco, map TFree vs);
    76     val ty = Type (tyco, map TFree vs);
    77     val cs = (map o apsnd o map o map_atyps)
    77     val cs = (map o apsnd o apsnd o map o map_atyps)
    78       (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_cs;
    78       (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_cs;
    79     val const = AxClass.param_of_inst thy (@{const_name term_of}, tyco);
    79     val const = AxClass.param_of_inst thy (@{const_name term_of}, tyco);
    80     val eqs = map (mk_term_of_eq thy ty) cs;
    80     val eqs = map (mk_term_of_eq thy ty) cs;
    81  in
    81  in
    82     thy
    82     thy
   119     thy
   119     thy
   120     |> Code.del_eqns const
   120     |> Code.del_eqns const
   121     |> Code.add_eqn eq
   121     |> Code.add_eqn eq
   122   end;
   122   end;
   123 
   123 
   124 fun ensure_abs_term_of_code (tyco, (raw_vs, ((abs, ty), (proj, _)))) thy =
   124 fun ensure_abs_term_of_code (tyco, (raw_vs, ((abs, (_, ty)), (proj, _)))) thy =
   125   let
   125   let
   126     val has_inst = can (Sorts.mg_domain (Sign.classes_of thy) tyco) @{sort term_of};
   126     val has_inst = can (Sorts.mg_domain (Sign.classes_of thy) tyco) @{sort term_of};
   127   in if has_inst then add_abs_term_of_code tyco raw_vs abs ty proj thy else thy end;
   127   in if has_inst then add_abs_term_of_code tyco raw_vs abs ty proj thy else thy end;
   128 
   128 
   129 
   129