+let saturate ?(delta=0) metasenv subst context ty goal_arity =
+ assert (goal_arity >= 0);
+ let rec aux metasenv = function
+ | NCic.Prod (name,s,t) as ty ->
+ let metasenv1, _, arg,_ =
+ NCicMetaSubst.mk_meta ~name:name metasenv context (`WithType s) in
+ let t, metasenv1, args, pno =
+ aux metasenv1 (NCicSubstitution.subst arg t)
+ in
+ if pno + 1 = goal_arity then
+ ty, metasenv, [], goal_arity+1
+ else
+ t, metasenv1, arg::args, pno+1
+ | ty ->
+ match NCicReduction.whd ~subst context ty ~delta with
+ | NCic.Prod _ as ty -> aux metasenv ty
+ | _ -> ty, metasenv, [], 0 (* differs from the other impl in this line*)
+ in
+ let res, newmetasenv, arguments, _ = aux metasenv ty in
+ res, newmetasenv, arguments
+;;