]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/basic_ag/bagType.ml
we added the implicit coercion for modus tollens
[helm.git] / helm / software / lambda-delta / basic_ag / bagType.ml
index 52c485ae740426c3a178d03efd4438593905390a..80b883ff44612101b47dcead611ef55aa88b438a 100644 (file)
@@ -10,6 +10,7 @@
       V_______________________________________________________________ *)
 
 module U = NUri
+module C = Cps
 module S = Share
 module L = Log
 module H = Hierarchy
@@ -35,6 +36,46 @@ let mk_gref u l =
    let map t v = B.Appl (v, t) in
    List.fold_left map (B.GRef u) l
 
+let add_coercion f t (i, uri, vs) =
+   let rec add f x = match x with
+      | B.Sort _
+      | B.LRef _
+      | B.GRef _                       -> f x
+      | B.Cast (u, t)                  -> 
+         let f uu =
+           let f tt = f (S.sh2 u uu t tt x B.cast) in
+           add f t
+        in
+         add f u
+      | B.Appl (v, t)                  ->
+         let f vv =
+           let f tt = f (S.sh2 v vv t tt x B.appl) in
+           add f t
+        in
+         add f v
+      | B.Bind (l, _, _, _) when i = l -> 
+         if U.eq uri I.imp then f (mk_gref I.mt (vs @ [x])) else
+        assert false
+      | B.Bind (l, id, B.Abst w, t)    ->
+         let f ww =
+           let f tt = f (S.sh2 w ww t tt x (B.bind_abst l id)) in
+           add f t
+        in
+        add f w
+      | B.Bind (l, id, B.Abbr v, t)    ->
+         let f vv =
+           let f tt = f (S.sh2 v vv t tt x (B.bind_abbr l id)) in
+           add f t
+        in
+        add f v
+      | B.Bind (l, id, B.Void, t)      ->
+         let f tt = f (S.sh1 t tt x (B.bind l id B.Void)) in
+        add f t
+   in
+   add f t
+
+let add_coercions f = C.list_fold_left f add_coercion
+
 (* Interface functions ******************************************************)
 
 let rec b_type_of f g c x = 
@@ -93,24 +134,29 @@ let rec b_type_of f g c x =
             L.box (succ level);
            L.log O.specs (succ level) (L.ct_items1 "Just scanned" cc w);
            L.unbox (succ level);
-           let f b =
-              if b then f (S.sh2 v xv t xt x B.appl) (B.appl xv tt) else
-              error2 "the term" cc xv "must be of type" cc w
+           let f = function
+              | Some l -> f (S.sh2 v xv t xt x B.appl) (B.appl xv tt)
+              | None   -> error2 "the term" cc xv "must be of type" cc w
            in
            R.are_convertible f cc w vv     
       in
       let f xv vv xt = function
 (* inserting a missing "modus ponens" *)      
-         | B.Appl (y2, B.Appl (y1, B.GRef u)) when U.eq u I.imp ->
+         | B.Appl (y2, B.Appl (y1, B.GRef uri)) when U.eq uri I.imp ->
             b_type_of f g c (mk_gref I.mp [y1; y2; xv; xt])
-         | tt -> R.ho_whd (h xv vv xt tt) c tt
+         | B.Appl (y1, B.GRef uri) when U.eq uri I.not ->
+            b_type_of f g c (mk_gref I.mp [y1; B.GRef I.con; xv; xt])   
+        | tt -> R.ho_whd (h xv vv xt tt) c tt
       in
       let f xv vv = b_type_of (f xv vv) g c t in
       type_of f g c v
    | B.Cast (u, t)            ->
-      let f xu xt b = 
-         if b then f (S.sh2 u xu t xt x B.cast) xu else
-        error2 "the term" c xt "must be of type" c xu
+      let f xu xt = function 
+         | Some [] -> f (S.sh2 u xu t xt x B.cast) xu
+        | Some l  ->
+           let f xt = type_of f g c (S.sh2 u xu t xt x B.cast) in
+           add_coercions f xt l
+        | None    -> error2 "the term" c xt "must be of type" c xu
       in
       let f xu xt tt = R.are_convertible (f xu xt) c xu tt in
       let f xu _ = b_type_of (f xu) g c t in
@@ -119,3 +165,4 @@ let rec b_type_of f g c x =
 and type_of f g c x =
    let f t u = L.unbox level; f t u in
    L.box level; b_type_of f g c x
+