]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_unification/cicUnification.ml
Sorts are no longer all convertible. To be completed once that universes
[helm.git] / helm / ocaml / cic_unification / cicUnification.ml
index 9c2dde84b45dd1aef507d2a6a00d3c8dcfb8e818..c56fb087423c457c3c599053544ec4e1ce0ab4f4 100644 (file)
@@ -92,15 +92,28 @@ let rec fo_unif_subst subst context metasenv t1 t2 =
           raise (UnificationFailure (sprintf
             "Error trying to unify %s with %s: the algorithm tried to check whether the two substitutions are convertible; if they are not, it tried to unify the two substitutions. No restriction was attempted."
             (CicMetaSubst.ppterm subst t1) (CicMetaSubst.ppterm subst t2)))
-   | (C.Meta (n,l), C.Meta (m,_)) when n>m ->
+   | (C.Meta (n,_), C.Meta (m,_)) when n>m ->
        fo_unif_subst subst context metasenv t2 t1
    | (C.Meta (n,l), t)   
    | (t, C.Meta (n,l)) ->
+       let fo_unif_subst =
+        let (lower,upper) =
+         match t1,t2 with
+            C.Meta (n,_), C.Meta (m,_) when n < m ->
+             (fun t1 t2 -> t1), (fun t1 t2 -> t2)
+          | _, C.Meta _ ->
+             (fun t1 t2 -> t1), (fun t1 t2 -> t2)
+          | _,_ ->
+             (fun t1 t2 -> t2), (fun t1 t2 -> t1)
+        in
+         fun subst context metasenv m1 m2 ->
+          fo_unif_subst subst context metasenv (lower m1 m2) (upper m1 m2)
+       in
        let subst'',metasenv' =
         try
          let oldt = (List.assoc n subst) in
          let lifted_oldt = S.lift_meta l oldt in
-          fo_unif_subst subst context metasenv lifted_oldt t
+          fo_unif_subst subst context metasenv t lifted_oldt
         with Not_found ->
          let t',metasenv',subst' =
           try
@@ -116,7 +129,7 @@ let rec fo_unif_subst subst context metasenv t1 t2 =
           let tyt =
             type_of_aux' metasenv' subst'' context t
           in
-           fo_unif_subst subst'' context metasenv' (S.lift_meta l meta_type) tyt
+           fo_unif_subst subst'' context metasenv' tyt (S.lift_meta l meta_type)
         with AssertFailure _ ->
           (* TODO huge hack!!!!
            * we keep on unifying/refining in the hope that the problem will be