allow_coercions subst metasenv context he hetype args_bo_and_ty ugraph
=
(* aux function to add coercions to funclass *)
- let rec fix_arity metasenv context subst he hetype args_bo_and_ty ugraph =
+ let rec fix_arity metasenv context subst he hetype eaten args_bo_and_ty ugraph =
(* {{{ body *)
let pristinemenv = metasenv in
let metasenv,hetype' =
let args, remainder =
HExtlib.split_nth how_many_args_are_needed args_bo_and_ty
in
- let args = List.map fst args in
+ let args = List.map fst (eaten@args) in
let x =
if args <> [] then
match he with
match
HExtlib.list_findopt
(fun (metasenv,last,coerc) ->
+ debug_print (lazy ("Tentative " ^ CicMetaSubst.ppterm ~metasenv subst coerc));
+ debug_print (lazy ("Last " ^ CicMetaSubst.ppterm ~metasenv subst last));
+ debug_print (lazy ("x " ^ CicMetaSubst.ppterm ~metasenv subst x));
let subst,metasenv,ugraph =
fo_unif_subst subst context metasenv last x ugraph in
- debug_print (lazy ("Tentative " ^ CicMetaSubst.ppterm ~metasenv subst coerc));
try
(* we want this to be available in the error handler fo the
* following (so it has its own try. *)
try
let subst,metasenv,ugraph,hetype',he,args_bo_and_ty =
fix_arity
- metasenv context subst t tty remainder ugraph
+ metasenv context subst t tty [] remainder ugraph
in
Some (subst,metasenv,ugraph,hetype',he,args_bo_and_ty)
with Uncertain _ | RefineFailure _ -> None
(* {{{ body *)
function
| [] -> newargs,subst,metasenv,he,hetype,ugraph
- | (hete, hety)::tl ->
+ | (hete, hety)::tl as rest ->
match (CicReduction.whd ~subst context hetype) with
| Cic.Prod (n,s,t) ->
let arg,subst,metasenv,ugraph =
let subst,metasenv,ugraph1,hetype',he,args_bo_and_ty =
fix_arity
pristinemenv context subst he hetype
- (newargs@[hete,hety]@tl) ugraph
+ newargs rest ugraph
in
eat_prods_and_args metasenv
metasenv subst context pristinehe he hetype'
else
(* this (says CSC) is also useful to infer dependent types *)
try
- fix_arity metasenv context subst he hetype args_bo_and_ty ugraph
+ fix_arity metasenv context subst he hetype [] args_bo_and_ty ugraph
with RefineFailure _ | Uncertain _ as exn ->
(* unable to fix arity *)
more_args_than_expected localization_tbl metasenv
| CoercGraph.NotHandled _ -> raise (RefineFailure (lazy
"coerce_atom_to_something fails since no coercions found"))
| CoercGraph.SomeCoercion candidates ->
+ debug_print (lazy (string_of_int (List.length candidates) ^ "
+ candidates found"));
let uncertain = ref false in
let selected =
(* HExtlib.list_findopt *)
HExtlib.filter_map
(fun (metasenv,last,c) ->
try
+ debug_print (lazy ("FO_UNIF_SUBST: " ^
+ CicMetaSubst.ppterm_in_context ~metasenv subst last context ^
+ " <==> " ^
+ CicMetaSubst.ppterm_in_context ~metasenv subst t context));
+ debug_print (lazy ("FO_UNIF_SUBST: " ^
+ CicPp.ppterm last ^ " <==> " ^ CicPp.ppterm t));
let subst,metasenv,ugraph =
- fo_unif_subst subst context metasenv last t ugraph in
+ fo_unif_subst subst context metasenv last t ugraph
+ in
+
let newt,newhety,subst,metasenv,ugraph =
type_of_aux subst metasenv context c ugraph in
let newt, newty, subst, metasenv, ugraph =
let infty = clean infty subst context in
let expty = clean expty subst context in
let t = clean t subst context in
+ debug_print (lazy ("COERCE_TO_SOMETHING: " ^
+ CicMetaSubst.ppterm_in_context ~metasenv subst t context ^ " : " ^
+ CicMetaSubst.ppterm_in_context ~metasenv subst infty context ^ " ==> " ^
+ CicMetaSubst.ppterm_in_context ~metasenv subst expty context));
match infty, expty, t with
| Cic.Prod (nameprod,src,ty), Cic.Prod (_,src2,ty2), Cic.Fix (n,fl) ->
debug_print (lazy "FIX");
~metasenv subst coerced context));
(coerced, expty), subst, metasenv, ugraph
| _ ->
- debug_print (lazy "ATOM");
+ debug_print (lazy ("ATOM: " ^ CicMetaSubst.ppterm_in_context
+ ~metasenv subst infty context ^ " ==> " ^
+ CicMetaSubst.ppterm_in_context ~metasenv subst expty context));
coerce_atom_to_something t infty expty subst metasenv context ugraph
in
try