NCicUnification.unify hdb metasenv subst context resty expty
in
*)
- let _, metasenv, subst, pl_rev =
- List.fold_left
- (fun (j, metasenv, subst, branches) p ->
+ let _, metasenv, subst, pl =
+ List.fold_right
+ (fun p (j, metasenv, subst, branches) ->
let cons =
let cons = Ref.mk_constructor j r in
if parameters = [] then C.Const cons
NCicPp.ppterm ~metasenv ~subst ~context ty_branch ));
let metasenv, subst, p, _ =
typeof_aux metasenv subst context (Some ty_branch) p in
- j+1, metasenv, subst, p :: branches)
- (1, metasenv, subst, []) pl
+ j-1, metasenv, subst, p :: branches)
+ pl (List.length pl, metasenv, subst, [])
in
let resty = C.Appl (outtype::arguments@[term]) in
let resty = NCicReduction.head_beta_reduce ~subst resty in
- metasenv, subst, C.Match (r, outtype, term, List.rev pl_rev),resty
+ metasenv, subst, C.Match (r, outtype, term, pl),resty
| C.Match _ -> assert false
in
pp (lazy (NCicPp.ppterm ~metasenv ~subst ~context t ^ " :: "^
match NCicReduction.whd ~subst context ty with
| C.Meta (_,(0,(C.Irl 0 | C.Ctx []))) as ty ->
metasenv, subst, t, ty
- | C.Meta (i,(_,(C.Irl 0 | C.Ctx []))) ->
- metasenv, subst, t, C.Meta(i,(0,C.Irl 0))
+ | C.Meta (_i,(_,(C.Irl 0 | C.Ctx []))) -> assert false (*CSC: ???
+ metasenv, subst, t, C.Meta(i,(0,C.Irl 0)) *)
| C.Meta (i,(_,lc)) ->
let len = match lc with C.Irl len->len | C.Ctx l->List.length l in
let metasenv, subst, newmeta =
in
aux metasenv subst [] newhead newheadty (arg :: tl)
in
- aux metasenv subst [] he ty_he args
+ (* We need to reverse the order of the new created metas since they
+ are pushed on top of the metasenv in the wrong order *)
+ let highest_meta = NCicMetaSubst.maxmeta () in
+ let metasenv, subst, newhead, newheadty =
+ aux metasenv subst [] he ty_he args in
+ let metasenv_old,metasenv_new =
+ List.partition (fun (i,_) -> i <= highest_meta) metasenv
+ in
+ (List.rev metasenv_new) @ metasenv_old, subst, newhead, newheadty
(*D*)in outside(); rc with exc -> outside (); raise exc
;;
?(localise=fun _ -> Stdpp.dummy_loc)
~look_for_coercion (uri,height,metasenv,subst,obj)
=
+prerr_endline ("===============\n" ^ NCicPp.ppobj (uri,height,metasenv,subst,obj));
let check_type metasenv subst context (ty as orig_ty) = (* XXX fattorizza *)
let metasenv, subst, ty, sort =
typeof hdb ~localise ~look_for_coercion metasenv subst context ty None
try snd (HExtlib.split_nth leftno k_relev)
with Failure _ -> k_relev in
let te = NCicTypeChecker.debruijn uri len [] te in
+ let metasenv, subst, te, _ = check_type metasenv subst tys te in
let context,te = NCicReduction.split_prods ~subst tys leftno te in
let _,chopped_context_rev =
HExtlib.split_nth (List.length tys) (List.rev context) in
else
metasenv,subst,item1::context
) (metasenv,subst,[]) sx_context_ty_rev sx_context_te_rev
- with Invalid_argument "List.fold_left2" -> assert false
- in
- let metasenv, subst, te, con_sort =
- check_type metasenv subst context te
- in
+ with Invalid_argument "List.fold_left2" -> assert false in
+ let con_sort= NCicTypeChecker.typeof ~subst ~metasenv context te in
(match
NCicReduction.whd ~subst context con_sort,
NCicReduction.whd ~subst [] ty_sort