tuned handling of type variable names further
authorhaftmann
Mon Oct 05 15:04:45 2009 +0200 (2009-10-05)
changeset 32873333945c9ac6a
parent 32872 019201eb7e07
child 32874 5281cebb1a37
tuned handling of type variable names further
src/Pure/Isar/code.ML
src/Tools/Code/code_preproc.ML
src/Tools/Code/code_thingol.ML
     1.1 --- a/src/Pure/Isar/code.ML	Mon Oct 05 08:36:33 2009 +0200
     1.2 +++ b/src/Pure/Isar/code.ML	Mon Oct 05 15:04:45 2009 +0200
     1.3 @@ -13,7 +13,6 @@
     1.4    val read_const: theory -> string -> string
     1.5    val string_of_const: theory -> string -> string
     1.6    val args_number: theory -> string -> int
     1.7 -  val typscheme: theory -> string * typ -> (string * sort) list * typ
     1.8  
     1.9    (*constructor sets*)
    1.10    val constrset_of_consts: theory -> (string * typ) list
    1.11 @@ -28,8 +27,7 @@
    1.12      -> (thm * bool) list -> (thm * bool) list
    1.13    val const_typ_eqn: theory -> thm -> string * typ
    1.14    val typscheme_eqn: theory -> thm -> (string * sort) list * typ
    1.15 -  val typscheme_rhss_eqns: theory -> string -> thm list
    1.16 -    -> ((string * sort) list * typ) * (string * typ list) list
    1.17 +  val typscheme_eqns: theory -> string -> thm list -> (string * sort) list * typ
    1.18  
    1.19    (*executable code*)
    1.20    val add_datatype: (string * typ) list -> theory -> theory
    1.21 @@ -114,19 +112,6 @@
    1.22  
    1.23  fun read_const thy = AxClass.unoverload_const thy o read_bare_const thy;
    1.24  
    1.25 -fun typscheme thy (c, ty) =
    1.26 -  let
    1.27 -    val ty' = Logic.unvarifyT ty;
    1.28 -  in (map dest_TFree (Sign.const_typargs thy (c, ty')), Type.strip_sorts ty') end;
    1.29 -
    1.30 -fun default_typscheme thy c =
    1.31 -  let
    1.32 -    val ty = (snd o dest_Const o Term_Subst.zero_var_indexes o curry Const c
    1.33 -      o Type.strip_sorts o Sign.the_const_type thy) c;
    1.34 -  in case AxClass.class_of_param thy c
    1.35 -   of SOME class => ([(Name.aT, [class])], ty)
    1.36 -    | NONE => typscheme thy (c, ty)
    1.37 -  end;
    1.38  
    1.39  
    1.40  (** data store **)
    1.41 @@ -522,18 +507,22 @@
    1.42      val (c, ty) = head_eqn thm;
    1.43      val c' = AxClass.unoverload_const thy (c, ty);
    1.44    in (c', ty) end;
    1.45 -
    1.46 -fun typscheme_eqn thy = typscheme thy o const_typ_eqn thy;
    1.47  fun const_eqn thy = fst o const_typ_eqn thy;
    1.48  
    1.49 -fun consts_of thy thms = [] |> (fold o fold o fold_aterms)
    1.50 -  (fn Const (c, ty) => insert (op =) (c, Sign.const_typargs thy (c, Logic.unvarifyT ty)) | _ => I)
    1.51 -    (map (op :: o swap o apfst (snd o strip_comb) o Logic.dest_equals o Thm.plain_prop_of) thms);
    1.52 -
    1.53 -fun typscheme_rhss_eqns thy c [] =
    1.54 -      (default_typscheme thy c, [])
    1.55 -  | typscheme_rhss_eqns thy c (thms as thm :: _) =
    1.56 -      (typscheme_eqn thy thm, consts_of thy thms);
    1.57 +fun typscheme thy (c, ty) =
    1.58 +  (map dest_TFree (Sign.const_typargs thy (c, ty)), Type.strip_sorts ty);
    1.59 +fun typscheme_eqn thy = typscheme thy o apsnd Logic.unvarifyT o const_typ_eqn thy;
    1.60 +fun typscheme_eqns thy c [] = 
    1.61 +      let
    1.62 +        val raw_ty = Sign.the_const_type thy c;
    1.63 +        val tvars = Term.add_tvar_namesT raw_ty [];
    1.64 +        val tvars' = case AxClass.class_of_param thy c
    1.65 +         of SOME class => [TFree (Name.aT, [class])]
    1.66 +          | NONE => Name.invent_list [] Name.aT (length tvars)
    1.67 +              |> map (fn v => TFree (v, []));
    1.68 +        val ty = typ_subst_TVars (tvars ~~ tvars') raw_ty;
    1.69 +      in typscheme thy (c, ty) end
    1.70 +  | typscheme_eqns thy c (thms as thm :: _) = typscheme_eqn thy thm;
    1.71  
    1.72  fun assert_eqns_const thy c eqns =
    1.73    let
    1.74 @@ -549,7 +538,7 @@
    1.75      fun inter_sorts vs =
    1.76        fold (curry (Sorts.inter_sort (Sign.classes_of thy)) o snd) vs [];
    1.77      val sorts = map_transpose inter_sorts vss;
    1.78 -    val vts = Name.names Name.context "'X" sorts
    1.79 +    val vts = Name.names Name.context Name.aT sorts
    1.80        |> map (fn (v, sort) => TVar ((v, 0), sort));
    1.81    in map2 (fn vs => Thm.certify_instantiate (vs ~~ vts, [])) vss thms end;
    1.82  
     2.1 --- a/src/Tools/Code/code_preproc.ML	Mon Oct 05 08:36:33 2009 +0200
     2.2 +++ b/src/Tools/Code/code_preproc.ML	Mon Oct 05 15:04:45 2009 +0200
     2.3 @@ -19,7 +19,7 @@
     2.4    type code_algebra
     2.5    type code_graph
     2.6    val eqns: code_graph -> string -> (thm * bool) list
     2.7 -  val typ: code_graph -> string -> (string * sort) list * typ
     2.8 +  val sortargs: code_graph -> string -> sort list
     2.9    val all: code_graph -> string list
    2.10    val pretty: theory -> code_graph -> Pretty.T
    2.11    val obtain: theory -> string list -> term list -> code_algebra * code_graph
    2.12 @@ -62,7 +62,7 @@
    2.13    val empty = make_thmproc ((Simplifier.empty_ss, Simplifier.empty_ss), []);
    2.14    fun copy spec = spec;
    2.15    val extend = copy;
    2.16 -  fun merge pp = merge_thmproc;
    2.17 +  fun merge _ = merge_thmproc;
    2.18  );
    2.19  
    2.20  fun the_thmproc thy = case Code_Preproc_Data.get thy
    2.21 @@ -196,10 +196,10 @@
    2.22  (** sort algebra and code equation graph types **)
    2.23  
    2.24  type code_algebra = (sort -> sort) * Sorts.algebra;
    2.25 -type code_graph = (((string * sort) list * typ) * (thm * bool) list) Graph.T;
    2.26 +type code_graph = ((string * sort) list * (thm * bool) list) Graph.T;
    2.27  
    2.28  fun eqns eqngr = these o Option.map snd o try (Graph.get_node eqngr);
    2.29 -fun typ eqngr = fst o Graph.get_node eqngr;
    2.30 +fun sortargs eqngr = map snd o fst o Graph.get_node eqngr
    2.31  fun all eqngr = Graph.keys eqngr;
    2.32  
    2.33  fun pretty thy eqngr =
    2.34 @@ -227,6 +227,14 @@
    2.35    map (fn (c, _) => AxClass.param_of_inst thy (c, tyco))
    2.36      o maps (#params o AxClass.get_info thy);
    2.37  
    2.38 +fun typscheme_rhss thy c eqns =
    2.39 +  let
    2.40 +    val tyscm = Code.typscheme_eqns thy c (map fst eqns);
    2.41 +    val rhss = [] |> (fold o fold o fold_aterms)
    2.42 +      (fn Const (c, ty) => insert (op =) (c, Sign.const_typargs thy (c, Logic.unvarifyT ty)) | _ => I)
    2.43 +        (map (op :: o swap o apfst (snd o strip_comb) o Logic.dest_equals o Thm.plain_prop_of o fst) eqns);
    2.44 +  in (tyscm, rhss) end;
    2.45 +
    2.46  
    2.47  (* data structures *)
    2.48  
    2.49 @@ -262,11 +270,11 @@
    2.50  
    2.51  fun obtain_eqns thy eqngr c =
    2.52    case try (Graph.get_node eqngr) c
    2.53 -   of SOME ((lhs, _), eqns) => ((lhs, []), [])
    2.54 +   of SOME (lhs, eqns) => ((lhs, []), [])
    2.55      | NONE => let
    2.56          val eqns = Code.these_eqns thy c
    2.57            |> preprocess thy c;
    2.58 -        val ((lhs, _), rhss) = Code.typscheme_rhss_eqns thy c (map fst eqns);
    2.59 +        val ((lhs, _), rhss) = typscheme_rhss thy c eqns;
    2.60        in ((lhs, rhss), eqns) end;
    2.61  
    2.62  fun obtain_instance thy arities (inst as (class, tyco)) =
    2.63 @@ -413,11 +421,11 @@
    2.64        Vartab.update ((v, 0), sort)) lhs;
    2.65      val eqns = proto_eqns
    2.66        |> (map o apfst) (inst_thm thy inst_tab);
    2.67 -    val (tyscm, rhss') = Code.typscheme_rhss_eqns thy c (map fst eqns);
    2.68 -    val eqngr' = Graph.new_node (c, (tyscm, eqns)) eqngr;
    2.69 +    val ((vs, _), rhss') = typscheme_rhss thy c eqns;
    2.70 +    val eqngr' = Graph.new_node (c, (vs, eqns)) eqngr;
    2.71    in (map (pair c) rhss' @ rhss, eqngr') end;
    2.72  
    2.73 -fun extend_arities_eqngr thy cs ts (arities, eqngr) =
    2.74 +fun extend_arities_eqngr thy cs ts (arities, (eqngr : code_graph)) =
    2.75    let
    2.76      val cs_rhss = (fold o fold_aterms) (fn Const (c_ty as (c, _)) =>
    2.77        insert (op =) (c, (map (styp_of NONE) o Sign.const_typargs thy) c_ty) | _ => I) ts [];
    2.78 @@ -430,7 +438,7 @@
    2.79        (AList.lookup (op =) arities') (Sign.classes_of thy);
    2.80      val (rhss, eqngr') = Symtab.fold (add_eqs thy vardeps) eqntab ([], eqngr);
    2.81      fun deps_of (c, rhs) = c :: maps (dicts_of thy algebra)
    2.82 -      (rhs ~~ (map snd o fst o fst o Graph.get_node eqngr') c);
    2.83 +      (rhs ~~ sortargs eqngr' c);
    2.84      val eqngr'' = fold (fn (c, rhs) => fold
    2.85        (curry Graph.add_edge c) (deps_of rhs)) rhss eqngr';
    2.86    in (algebra, (arities', eqngr'')) end;
     3.1 --- a/src/Tools/Code/code_thingol.ML	Mon Oct 05 08:36:33 2009 +0200
     3.2 +++ b/src/Tools/Code/code_thingol.ML	Mon Oct 05 15:04:45 2009 +0200
     3.3 @@ -533,62 +533,62 @@
     3.4  
     3.5  (* translation *)
     3.6  
     3.7 -fun ensure_tyco thy algbr funcgr tyco =
     3.8 +fun ensure_tyco thy algbr eqngr tyco =
     3.9    let
    3.10      val stmt_datatype =
    3.11        let
    3.12          val (vs, cos) = Code.get_datatype thy tyco;
    3.13        in
    3.14 -        fold_map (translate_tyvar_sort thy algbr funcgr) vs
    3.15 +        fold_map (translate_tyvar_sort thy algbr eqngr) vs
    3.16          ##>> fold_map (fn (c, tys) =>
    3.17 -          ensure_const thy algbr funcgr c
    3.18 -          ##>> fold_map (translate_typ thy algbr funcgr) tys) cos
    3.19 +          ensure_const thy algbr eqngr c
    3.20 +          ##>> fold_map (translate_typ thy algbr eqngr) tys) cos
    3.21          #>> (fn info => Datatype (tyco, info))
    3.22        end;
    3.23    in ensure_stmt lookup_tyco (declare_tyco thy) stmt_datatype tyco end
    3.24 -and ensure_const thy algbr funcgr c =
    3.25 +and ensure_const thy algbr eqngr c =
    3.26    let
    3.27      fun stmt_datatypecons tyco =
    3.28 -      ensure_tyco thy algbr funcgr tyco
    3.29 +      ensure_tyco thy algbr eqngr tyco
    3.30        #>> (fn tyco => Datatypecons (c, tyco));
    3.31      fun stmt_classparam class =
    3.32 -      ensure_class thy algbr funcgr class
    3.33 +      ensure_class thy algbr eqngr class
    3.34        #>> (fn class => Classparam (c, class));
    3.35      fun stmt_fun raw_eqns =
    3.36        let
    3.37          val eqns = burrow_fst (clean_thms thy) raw_eqns;
    3.38 -        val ((vs, ty), _) = Code.typscheme_rhss_eqns thy c (map fst eqns);
    3.39 +        val (vs, ty) = Code.typscheme_eqns thy c (map fst eqns);
    3.40        in
    3.41 -        fold_map (translate_tyvar_sort thy algbr funcgr) vs
    3.42 -        ##>> translate_typ thy algbr funcgr ty
    3.43 -        ##>> fold_map (translate_eqn thy algbr funcgr) eqns
    3.44 +        fold_map (translate_tyvar_sort thy algbr eqngr) vs
    3.45 +        ##>> translate_typ thy algbr eqngr ty
    3.46 +        ##>> fold_map (translate_eqn thy algbr eqngr) eqns
    3.47          #>> (fn info => Fun (c, info))
    3.48        end;
    3.49      val stmt_const = case Code.get_datatype_of_constr thy c
    3.50       of SOME tyco => stmt_datatypecons tyco
    3.51        | NONE => (case AxClass.class_of_param thy c
    3.52           of SOME class => stmt_classparam class
    3.53 -          | NONE => stmt_fun (Code_Preproc.eqns funcgr c))
    3.54 +          | NONE => stmt_fun (Code_Preproc.eqns eqngr c))
    3.55    in ensure_stmt lookup_const (declare_const thy) stmt_const c end
    3.56 -and ensure_class thy (algbr as (_, algebra)) funcgr class =
    3.57 +and ensure_class thy (algbr as (_, algebra)) eqngr class =
    3.58    let
    3.59      val superclasses = (Sorts.minimize_sort algebra o Sorts.super_classes algebra) class;
    3.60      val cs = #params (AxClass.get_info thy class);
    3.61      val stmt_class =
    3.62 -      fold_map (fn superclass => ensure_class thy algbr funcgr superclass
    3.63 -        ##>> ensure_classrel thy algbr funcgr (class, superclass)) superclasses
    3.64 -      ##>> fold_map (fn (c, ty) => ensure_const thy algbr funcgr c
    3.65 -        ##>> translate_typ thy algbr funcgr ty) cs
    3.66 +      fold_map (fn superclass => ensure_class thy algbr eqngr superclass
    3.67 +        ##>> ensure_classrel thy algbr eqngr (class, superclass)) superclasses
    3.68 +      ##>> fold_map (fn (c, ty) => ensure_const thy algbr eqngr c
    3.69 +        ##>> translate_typ thy algbr eqngr ty) cs
    3.70        #>> (fn info => Class (class, (unprefix "'" Name.aT, info)))
    3.71    in ensure_stmt lookup_class (declare_class thy) stmt_class class end
    3.72 -and ensure_classrel thy algbr funcgr (subclass, superclass) =
    3.73 +and ensure_classrel thy algbr eqngr (subclass, superclass) =
    3.74    let
    3.75      val stmt_classrel =
    3.76 -      ensure_class thy algbr funcgr subclass
    3.77 -      ##>> ensure_class thy algbr funcgr superclass
    3.78 +      ensure_class thy algbr eqngr subclass
    3.79 +      ##>> ensure_class thy algbr eqngr superclass
    3.80        #>> Classrel;
    3.81    in ensure_stmt lookup_classrel (declare_classrel thy) stmt_classrel (subclass, superclass) end
    3.82 -and ensure_inst thy (algbr as (_, algebra)) funcgr (class, tyco) =
    3.83 +and ensure_inst thy (algbr as (_, algebra)) eqngr (class, tyco) =
    3.84    let
    3.85      val superclasses = (Sorts.minimize_sort algebra o Sorts.super_classes algebra) class;
    3.86      val classparams = these (try (#params o AxClass.get_info thy) class);
    3.87 @@ -599,9 +599,9 @@
    3.88      val arity_typ = Type (tyco, map TFree vs);
    3.89      val arity_typ' = Type (tyco, map (fn (v, sort) => TVar ((v, 0), sort)) vs');
    3.90      fun translate_superarity superclass =
    3.91 -      ensure_class thy algbr funcgr superclass
    3.92 -      ##>> ensure_classrel thy algbr funcgr (class, superclass)
    3.93 -      ##>> translate_dicts thy algbr funcgr NONE (arity_typ, [superclass])
    3.94 +      ensure_class thy algbr eqngr superclass
    3.95 +      ##>> ensure_classrel thy algbr eqngr (class, superclass)
    3.96 +      ##>> translate_dicts thy algbr eqngr NONE (arity_typ, [superclass])
    3.97        #>> (fn ((superclass, classrel), [DictConst (inst, dss)]) =>
    3.98              (superclass, (classrel, (inst, dss))));
    3.99      fun translate_classparam_inst (c, ty) =
   3.100 @@ -611,73 +611,73 @@
   3.101          val c_ty = (apsnd Logic.unvarifyT o dest_Const o snd
   3.102            o Logic.dest_equals o Thm.prop_of) thm;
   3.103        in
   3.104 -        ensure_const thy algbr funcgr c
   3.105 -        ##>> translate_const thy algbr funcgr (SOME thm) c_ty
   3.106 +        ensure_const thy algbr eqngr c
   3.107 +        ##>> translate_const thy algbr eqngr (SOME thm) c_ty
   3.108          #>> (fn (c, IConst c_inst) => ((c, c_inst), (thm, true)))
   3.109        end;
   3.110      val stmt_inst =
   3.111 -      ensure_class thy algbr funcgr class
   3.112 -      ##>> ensure_tyco thy algbr funcgr tyco
   3.113 -      ##>> fold_map (translate_tyvar_sort thy algbr funcgr) vs
   3.114 +      ensure_class thy algbr eqngr class
   3.115 +      ##>> ensure_tyco thy algbr eqngr tyco
   3.116 +      ##>> fold_map (translate_tyvar_sort thy algbr eqngr) vs
   3.117        ##>> fold_map translate_superarity superclasses
   3.118        ##>> fold_map translate_classparam_inst classparams
   3.119        #>> (fn ((((class, tyco), arity), superarities), classparams) =>
   3.120               Classinst ((class, (tyco, arity)), (superarities, classparams)));
   3.121    in ensure_stmt lookup_instance (declare_instance thy) stmt_inst (class, tyco) end
   3.122 -and translate_typ thy algbr funcgr (TFree (v, _)) =
   3.123 +and translate_typ thy algbr eqngr (TFree (v, _)) =
   3.124        pair (ITyVar (unprefix "'" v))
   3.125 -  | translate_typ thy algbr funcgr (Type (tyco, tys)) =
   3.126 -      ensure_tyco thy algbr funcgr tyco
   3.127 -      ##>> fold_map (translate_typ thy algbr funcgr) tys
   3.128 +  | translate_typ thy algbr eqngr (Type (tyco, tys)) =
   3.129 +      ensure_tyco thy algbr eqngr tyco
   3.130 +      ##>> fold_map (translate_typ thy algbr eqngr) tys
   3.131        #>> (fn (tyco, tys) => tyco `%% tys)
   3.132 -and translate_term thy algbr funcgr thm (Const (c, ty)) =
   3.133 -      translate_app thy algbr funcgr thm ((c, ty), [])
   3.134 -  | translate_term thy algbr funcgr thm (Free (v, _)) =
   3.135 +and translate_term thy algbr eqngr thm (Const (c, ty)) =
   3.136 +      translate_app thy algbr eqngr thm ((c, ty), [])
   3.137 +  | translate_term thy algbr eqngr thm (Free (v, _)) =
   3.138        pair (IVar (SOME v))
   3.139 -  | translate_term thy algbr funcgr thm (Abs (v, ty, t)) =
   3.140 +  | translate_term thy algbr eqngr thm (Abs (v, ty, t)) =
   3.141        let
   3.142          val (v', t') = Syntax.variant_abs (Name.desymbolize false v, ty, t);
   3.143          val v'' = if member (op =) (Term.add_free_names t' []) v'
   3.144            then SOME v' else NONE
   3.145        in
   3.146 -        translate_typ thy algbr funcgr ty
   3.147 -        ##>> translate_term thy algbr funcgr thm t'
   3.148 +        translate_typ thy algbr eqngr ty
   3.149 +        ##>> translate_term thy algbr eqngr thm t'
   3.150          #>> (fn (ty, t) => (v'', ty) `|=> t)
   3.151        end
   3.152 -  | translate_term thy algbr funcgr thm (t as _ $ _) =
   3.153 +  | translate_term thy algbr eqngr thm (t as _ $ _) =
   3.154        case strip_comb t
   3.155         of (Const (c, ty), ts) =>
   3.156 -            translate_app thy algbr funcgr thm ((c, ty), ts)
   3.157 +            translate_app thy algbr eqngr thm ((c, ty), ts)
   3.158          | (t', ts) =>
   3.159 -            translate_term thy algbr funcgr thm t'
   3.160 -            ##>> fold_map (translate_term thy algbr funcgr thm) ts
   3.161 +            translate_term thy algbr eqngr thm t'
   3.162 +            ##>> fold_map (translate_term thy algbr eqngr thm) ts
   3.163              #>> (fn (t, ts) => t `$$ ts)
   3.164 -and translate_eqn thy algbr funcgr (thm, proper) =
   3.165 +and translate_eqn thy algbr eqngr (thm, proper) =
   3.166    let
   3.167      val (args, rhs) = (apfst (snd o strip_comb) o Logic.dest_equals
   3.168        o Logic.unvarify o prop_of) thm;
   3.169    in
   3.170 -    fold_map (translate_term thy algbr funcgr (SOME thm)) args
   3.171 -    ##>> translate_term thy algbr funcgr (SOME thm) rhs
   3.172 +    fold_map (translate_term thy algbr eqngr (SOME thm)) args
   3.173 +    ##>> translate_term thy algbr eqngr (SOME thm) rhs
   3.174      #>> rpair (thm, proper)
   3.175    end
   3.176 -and translate_const thy algbr funcgr thm (c, ty) =
   3.177 +and translate_const thy algbr eqngr thm (c, ty) =
   3.178    let
   3.179      val tys = Sign.const_typargs thy (c, ty);
   3.180 -    val sorts = (map snd o fst o Code_Preproc.typ funcgr) c;
   3.181 +    val sorts = Code_Preproc.sortargs eqngr c;
   3.182      val tys_args = (fst o Term.strip_type) ty;
   3.183    in
   3.184 -    ensure_const thy algbr funcgr c
   3.185 -    ##>> fold_map (translate_typ thy algbr funcgr) tys
   3.186 -    ##>> fold_map (translate_dicts thy algbr funcgr thm) (tys ~~ sorts)
   3.187 -    ##>> fold_map (translate_typ thy algbr funcgr) tys_args
   3.188 +    ensure_const thy algbr eqngr c
   3.189 +    ##>> fold_map (translate_typ thy algbr eqngr) tys
   3.190 +    ##>> fold_map (translate_dicts thy algbr eqngr thm) (tys ~~ sorts)
   3.191 +    ##>> fold_map (translate_typ thy algbr eqngr) tys_args
   3.192      #>> (fn (((c, tys), iss), tys_args) => IConst (c, ((tys, iss), tys_args)))
   3.193    end
   3.194 -and translate_app_const thy algbr funcgr thm (c_ty, ts) =
   3.195 -  translate_const thy algbr funcgr thm c_ty
   3.196 -  ##>> fold_map (translate_term thy algbr funcgr thm) ts
   3.197 +and translate_app_const thy algbr eqngr thm (c_ty, ts) =
   3.198 +  translate_const thy algbr eqngr thm c_ty
   3.199 +  ##>> fold_map (translate_term thy algbr eqngr thm) ts
   3.200    #>> (fn (t, ts) => t `$$ ts)
   3.201 -and translate_case thy algbr funcgr thm (num_args, (t_pos, case_pats)) (c_ty, ts) =
   3.202 +and translate_case thy algbr eqngr thm (num_args, (t_pos, case_pats)) (c_ty, ts) =
   3.203    let
   3.204      fun arg_types num_args ty = (fst o chop num_args o fst o strip_type) ty;
   3.205      val tys = arg_types num_args (snd c_ty);
   3.206 @@ -721,14 +721,14 @@
   3.207                (constrs ~~ ts_clause);
   3.208        in ((t, ty), clauses) end;
   3.209    in
   3.210 -    translate_const thy algbr funcgr thm c_ty
   3.211 -    ##>> fold_map (fn (constr, n) => translate_const thy algbr funcgr thm constr #>> rpair n) constrs
   3.212 -    ##>> translate_typ thy algbr funcgr ty
   3.213 -    ##>> fold_map (translate_term thy algbr funcgr thm) ts
   3.214 +    translate_const thy algbr eqngr thm c_ty
   3.215 +    ##>> fold_map (fn (constr, n) => translate_const thy algbr eqngr thm constr #>> rpair n) constrs
   3.216 +    ##>> translate_typ thy algbr eqngr ty
   3.217 +    ##>> fold_map (translate_term thy algbr eqngr thm) ts
   3.218      #-> (fn (((t, constrs), ty), ts) =>
   3.219        `(fn (_, (naming, _)) => ICase (casify naming constrs ty ts, t `$$ ts)))
   3.220    end
   3.221 -and translate_app_case thy algbr funcgr thm (case_scheme as (num_args, _)) ((c, ty), ts) =
   3.222 +and translate_app_case thy algbr eqngr thm (case_scheme as (num_args, _)) ((c, ty), ts) =
   3.223    if length ts < num_args then
   3.224      let
   3.225        val k = length ts;
   3.226 @@ -736,24 +736,24 @@
   3.227        val ctxt = (fold o fold_aterms) Term.declare_term_frees ts Name.context;
   3.228        val vs = Name.names ctxt "a" tys;
   3.229      in
   3.230 -      fold_map (translate_typ thy algbr funcgr) tys
   3.231 -      ##>> translate_case thy algbr funcgr thm case_scheme ((c, ty), ts @ map Free vs)
   3.232 +      fold_map (translate_typ thy algbr eqngr) tys
   3.233 +      ##>> translate_case thy algbr eqngr thm case_scheme ((c, ty), ts @ map Free vs)
   3.234        #>> (fn (tys, t) => map2 (fn (v, _) => pair (SOME v)) vs tys `|==> t)
   3.235      end
   3.236    else if length ts > num_args then
   3.237 -    translate_case thy algbr funcgr thm case_scheme ((c, ty), Library.take (num_args, ts))
   3.238 -    ##>> fold_map (translate_term thy algbr funcgr thm) (Library.drop (num_args, ts))
   3.239 +    translate_case thy algbr eqngr thm case_scheme ((c, ty), Library.take (num_args, ts))
   3.240 +    ##>> fold_map (translate_term thy algbr eqngr thm) (Library.drop (num_args, ts))
   3.241      #>> (fn (t, ts) => t `$$ ts)
   3.242    else
   3.243 -    translate_case thy algbr funcgr thm case_scheme ((c, ty), ts)
   3.244 -and translate_app thy algbr funcgr thm (c_ty_ts as ((c, _), _)) =
   3.245 +    translate_case thy algbr eqngr thm case_scheme ((c, ty), ts)
   3.246 +and translate_app thy algbr eqngr thm (c_ty_ts as ((c, _), _)) =
   3.247    case Code.get_case_scheme thy c
   3.248 -   of SOME case_scheme => translate_app_case thy algbr funcgr thm case_scheme c_ty_ts
   3.249 -    | NONE => translate_app_const thy algbr funcgr thm c_ty_ts
   3.250 -and translate_tyvar_sort thy (algbr as (proj_sort, _)) funcgr (v, sort) =
   3.251 -  fold_map (ensure_class thy algbr funcgr) (proj_sort sort)
   3.252 +   of SOME case_scheme => translate_app_case thy algbr eqngr thm case_scheme c_ty_ts
   3.253 +    | NONE => translate_app_const thy algbr eqngr thm c_ty_ts
   3.254 +and translate_tyvar_sort thy (algbr as (proj_sort, _)) eqngr (v, sort) =
   3.255 +  fold_map (ensure_class thy algbr eqngr) (proj_sort sort)
   3.256    #>> (fn sort => (unprefix "'" v, sort))
   3.257 -and translate_dicts thy (algbr as (proj_sort, algebra)) funcgr thm (ty, sort) =
   3.258 +and translate_dicts thy (algbr as (proj_sort, algebra)) eqngr thm (ty, sort) =
   3.259    let
   3.260      datatype typarg =
   3.261          Global of (class * string) * typarg list list
   3.262 @@ -773,11 +773,11 @@
   3.263         type_variable = type_variable} (ty, proj_sort sort)
   3.264        handle Sorts.CLASS_ERROR e => not_wellsorted thy thm ty sort e;
   3.265      fun mk_dict (Global (inst, yss)) =
   3.266 -          ensure_inst thy algbr funcgr inst
   3.267 +          ensure_inst thy algbr eqngr inst
   3.268            ##>> (fold_map o fold_map) mk_dict yss
   3.269            #>> (fn (inst, dss) => DictConst (inst, dss))
   3.270        | mk_dict (Local (classrels, (v, (n, sort)))) =
   3.271 -          fold_map (ensure_classrel thy algbr funcgr) classrels
   3.272 +          fold_map (ensure_classrel thy algbr eqngr) classrels
   3.273            #>> (fn classrels => DictVar (classrels, (unprefix "'" v, (n, length sort))))
   3.274    in fold_map mk_dict typargs end;
   3.275  
   3.276 @@ -800,9 +800,9 @@
   3.277  
   3.278  val cached_program = Program.get;
   3.279  
   3.280 -fun invoke_generation thy (algebra, funcgr) f name =
   3.281 +fun invoke_generation thy (algebra, eqngr) f name =
   3.282    Program.change_yield thy (fn naming_program => (NONE, naming_program)
   3.283 -    |> f thy algebra funcgr name
   3.284 +    |> f thy algebra eqngr name
   3.285      |-> (fn name => fn (_, naming_program) => (name, naming_program)));
   3.286  
   3.287  
   3.288 @@ -814,8 +814,8 @@
   3.289        let
   3.290          val cs_all = Graph.all_succs program cs;
   3.291        in (cs, (naming, Graph.subgraph (member (op =) cs_all) program)) end;
   3.292 -    fun generate_consts thy algebra funcgr =
   3.293 -      fold_map (ensure_const thy algebra funcgr);
   3.294 +    fun generate_consts thy algebra eqngr =
   3.295 +      fold_map (ensure_const thy algebra eqngr);
   3.296    in
   3.297      invoke_generation thy (Code_Preproc.obtain thy cs []) generate_consts cs
   3.298      |-> project_consts
   3.299 @@ -824,15 +824,15 @@
   3.300  
   3.301  (* value evaluation *)
   3.302  
   3.303 -fun ensure_value thy algbr funcgr t =
   3.304 +fun ensure_value thy algbr eqngr t =
   3.305    let
   3.306      val ty = fastype_of t;
   3.307      val vs = fold_term_types (K (fold_atyps (insert (eq_fst op =)
   3.308        o dest_TFree))) t [];
   3.309      val stmt_value =
   3.310 -      fold_map (translate_tyvar_sort thy algbr funcgr) vs
   3.311 -      ##>> translate_typ thy algbr funcgr ty
   3.312 -      ##>> translate_term thy algbr funcgr NONE t
   3.313 +      fold_map (translate_tyvar_sort thy algbr eqngr) vs
   3.314 +      ##>> translate_typ thy algbr eqngr ty
   3.315 +      ##>> translate_term thy algbr eqngr NONE t
   3.316        #>> (fn ((vs, ty), t) => Fun
   3.317          (Term.dummy_patternN, ((vs, ty), [(([], t), (Drule.dummy_thm, true))])));
   3.318      fun term_value (dep, (naming, program1)) =
   3.319 @@ -850,10 +850,10 @@
   3.320      #> term_value
   3.321    end;
   3.322  
   3.323 -fun base_evaluator thy evaluator algebra funcgr vs t =
   3.324 +fun base_evaluator thy evaluator algebra eqngr vs t =
   3.325    let
   3.326      val (((naming, program), (((vs', ty'), t'), deps)), _) =
   3.327 -      invoke_generation thy (algebra, funcgr) ensure_value t;
   3.328 +      invoke_generation thy (algebra, eqngr) ensure_value t;
   3.329      val vs'' = map (fn (v, _) => (v, (the o AList.lookup (op =) vs o prefix "'") v)) vs';
   3.330    in evaluator naming program ((vs'', (vs', ty')), t') deps end;
   3.331