src/Tools/Code/code_thingol.ML
changeset 43329 84472e198515
parent 43326 47cf4bc789aa
child 44338 700008399ee5
equal deleted inserted replaced
43328:10d731b06ed7 43329:84472e198515
   235         val (vs_tys, t') = unfold_abs_eta tys t;
   235         val (vs_tys, t') = unfold_abs_eta tys t;
   236       in (v_ty :: vs_tys, t') end
   236       in (v_ty :: vs_tys, t') end
   237   | unfold_abs_eta tys t =
   237   | unfold_abs_eta tys t =
   238       let
   238       let
   239         val ctxt = fold_varnames Name.declare t Name.context;
   239         val ctxt = fold_varnames Name.declare t Name.context;
   240         val vs_tys = (map o apfst) SOME (Name.names ctxt "a" tys);
   240         val vs_tys = (map o apfst) SOME (Name.invent_names ctxt "a" tys);
   241       in (vs_tys, t `$$ map (IVar o fst) vs_tys) end;
   241       in (vs_tys, t `$$ map (IVar o fst) vs_tys) end;
   242 
   242 
   243 fun eta_expand k (c as (name, (_, tys)), ts) =
   243 fun eta_expand k (c as (name, (_, tys)), ts) =
   244   let
   244   let
   245     val j = length ts;
   245     val j = length ts;
   246     val l = k - j;
   246     val l = k - j;
   247     val _ = if l > length tys
   247     val _ = if l > length tys
   248       then error ("Impossible eta-expansion for constant " ^ quote name) else ();
   248       then error ("Impossible eta-expansion for constant " ^ quote name) else ();
   249     val ctxt = (fold o fold_varnames) Name.declare ts Name.context;
   249     val ctxt = (fold o fold_varnames) Name.declare ts Name.context;
   250     val vs_tys = (map o apfst) SOME
   250     val vs_tys = (map o apfst) SOME
   251       (Name.names ctxt "a" ((take l o drop j) tys));
   251       (Name.invent_names ctxt "a" ((take l o drop j) tys));
   252   in vs_tys `|==> IConst c `$$ ts @ map (IVar o fst) vs_tys end;
   252   in vs_tys `|==> IConst c `$$ ts @ map (IVar o fst) vs_tys end;
   253 
   253 
   254 fun contains_dict_var t =
   254 fun contains_dict_var t =
   255   let
   255   let
   256     fun cont_dict (Dict (_, d)) = cont_plain_dict d
   256     fun cont_dict (Dict (_, d)) = cont_plain_dict d
   669     val super_classes = (Sorts.minimize_sort algebra o Sorts.super_classes algebra) class;
   669     val super_classes = (Sorts.minimize_sort algebra o Sorts.super_classes algebra) class;
   670     val these_classparams = these o try (#params o AxClass.get_info thy);
   670     val these_classparams = these o try (#params o AxClass.get_info thy);
   671     val classparams = these_classparams class;
   671     val classparams = these_classparams class;
   672     val further_classparams = maps these_classparams
   672     val further_classparams = maps these_classparams
   673       ((Sorts.complete_sort algebra o Sorts.super_classes algebra) class);
   673       ((Sorts.complete_sort algebra o Sorts.super_classes algebra) class);
   674     val vs = Name.names Name.context "'a" (Sorts.mg_domain algebra tyco [class]);
   674     val vs = Name.invent_names Name.context "'a" (Sorts.mg_domain algebra tyco [class]);
   675     val sorts' = Sorts.mg_domain (Sign.classes_of thy) tyco [class];
   675     val sorts' = Sorts.mg_domain (Sign.classes_of thy) tyco [class];
   676     val vs' = map2 (fn (v, sort1) => fn sort2 => (v,
   676     val vs' = map2 (fn (v, sort1) => fn sort2 => (v,
   677       Sorts.inter_sort (Sign.classes_of thy) (sort1, sort2))) vs sorts';
   677       Sorts.inter_sort (Sign.classes_of thy) (sort1, sort2))) vs sorts';
   678     val arity_typ = Type (tyco, map TFree vs);
   678     val arity_typ = Type (tyco, map TFree vs);
   679     val arity_typ' = Type (tyco, map (fn (v, sort) => TVar ((v, 0), sort)) vs');
   679     val arity_typ' = Type (tyco, map (fn (v, sort) => TVar ((v, 0), sort)) vs');
   818   if length ts < num_args then
   818   if length ts < num_args then
   819     let
   819     let
   820       val k = length ts;
   820       val k = length ts;
   821       val tys = (take (num_args - k) o drop k o fst o strip_type) ty;
   821       val tys = (take (num_args - k) o drop k o fst o strip_type) ty;
   822       val ctxt = (fold o fold_aterms) Term.declare_term_frees ts Name.context;
   822       val ctxt = (fold o fold_aterms) Term.declare_term_frees ts Name.context;
   823       val vs = Name.names ctxt "a" tys;
   823       val vs = Name.invent_names ctxt "a" tys;
   824     in
   824     in
   825       fold_map (translate_typ thy algbr eqngr permissive) tys
   825       fold_map (translate_typ thy algbr eqngr permissive) tys
   826       ##>> translate_case thy algbr eqngr permissive some_thm case_scheme ((c, ty), ts @ map Free vs)
   826       ##>> translate_case thy algbr eqngr permissive some_thm case_scheme ((c, ty), ts @ map Free vs)
   827       #>> (fn (tys, t) => map2 (fn (v, _) => pair (SOME v)) vs tys `|==> t)
   827       #>> (fn (tys, t) => map2 (fn (v, _) => pair (SOME v)) vs tys `|==> t)
   828     end
   828     end