+ let rec mk_prod metasenv context =
+ function
+ [] ->
+ let (metasenv, idx) = CicMkImplicit.mk_implicit_type metasenv context in
+ let irl =
+ CicMkImplicit.identity_relocation_list_for_metavariable context
+ in
+ metasenv,Cic.Meta (idx, irl)
+ | (_,argty)::tl ->
+ let (metasenv, idx) = CicMkImplicit.mk_implicit_type metasenv context in
+ let irl =
+ CicMkImplicit.identity_relocation_list_for_metavariable context
+ in
+ let meta = Cic.Meta (idx,irl) in
+ let name =
+ (* The name must be fresh for context. *)
+ (* Nevertheless, argty is well-typed only in context. *)
+ (* Thus I generate a name (name_hint) in context and *)
+ (* then I generate a name --- using the hint name_hint *)
+ (* --- that is fresh in (context'@context). *)
+ let name_hint =
+ FreshNamesGenerator.mk_fresh_name
+ (CicMetaSubst.apply_subst_metasenv subst metasenv)
+ (CicMetaSubst.apply_subst_context subst context)
+ Cic.Anonymous
+ (CicMetaSubst.apply_subst subst argty)
+ in
+ (* [] and (Cic.Sort Cic.prop) are dummy: they will not be used *)
+ FreshNamesGenerator.mk_fresh_name
+ [] context name_hint (Cic.Sort Cic.Prop)
+ in
+ let metasenv,target =
+ mk_prod metasenv ((Some (name, Cic.Decl meta))::context) tl
+ in
+ metasenv,Cic.Prod (name,meta,target)
+ in
+ let metasenv,hetype' = mk_prod metasenv context tlbody_and_type in
+ let (subst, metasenv) =
+ fo_unif_subst subst context metasenv hetype hetype'
+ in
+ let rec eat_prods metasenv subst context hetype =
+ function
+ [] -> metasenv,subst,hetype
+ | (hete, hety)::tl ->
+ (match hetype with
+ Cic.Prod (n,s,t) ->
+ let subst,metasenv =
+ fo_unif_subst subst context metasenv hety s
+ in
+ eat_prods metasenv subst context
+ (CicMetaSubst.subst subst hete t) tl
+ | _ -> assert false
+ )
+ in
+ let metasenv,subst,t =
+ eat_prods metasenv subst context hetype' tlbody_and_type
+ in
+ t,subst,metasenv
+(*