\ / This software is distributed as is, NO WARRANTY.
V_______________________________________________________________ *)
+module L = Log
module B = Brg
+module O = BrgOutput
module E = BrgEnvironment
module R = BrgReduction
-exception TypeError of string Lazy.t
+exception TypeError of (R.context, B.term) Log.item list
(* Internal functions *******************************************************)
-let error msg = raise (TypeError (lazy msg))
+let error1 s c t =
+ raise (TypeError (L.ct_items1 s c t))
+
+let error2 s1 c1 t1 s2 c2 t2 =
+ raise (TypeError (L.ct_items2 s1 c1 t1 s2 c2 t2))
+
+let are_convertible f c t1 t2 =
+ L.log O.specs 4 (L.ct_items2 "Now converting" c t1 "and" c t2);
+ R.are_convertible f c t1 t2
(* Interface functions ******************************************************)
-let rec type_of f g c = function
- | B.Sort h -> f (B.Sort (g h))
- | B.LRef i ->
+let rec type_of f g c x =
+ L.log O.specs 5 (L.ct_items1 "now checking" c x);
+ match x with
+ | B.Sort h -> f (B.Sort (g h))
+ | B.LRef i ->
let f = function
- | B.Abst, w -> f w
- | B.Abbr, B.Cast (w, v) -> f w
- | B.Abbr, _ -> error "lref"
+ | B.Abst w -> f w
+ | B.Abbr (B.Cast (w, v)) -> f w
+ | B.Abbr _ -> assert false
+ | B.Void -> assert false
in
R.get f c i
- | B.GRef uri ->
+ | B.GRef uri ->
let f = function
- | _, _, B.Abst, w -> f w
- | _, _, B.Abbr, B.Cast (w, v) -> f w
- | _, _, B.Abbr, _ -> error "gref"
+ | _, _, B.Abst w -> f w
+ | _, _, B.Abbr (B.Cast (w, v)) -> f w
+ | _, _, B.Abbr _ -> assert false
+ | _, _, B.Void -> assert false
in
E.get_obj f uri
- | B.Bind (id, b, u, t) ->
- let f uu tt = match b, t with
- | B.Abst, _
- | B.Abbr, B.Cast _ -> f (B.Bind (id, b, u, tt))
- | _ -> f (B.Bind (id, b, B.Cast (uu, u), tt))
+ | B.Bind (id, B.Abbr u, t) ->
+ let f tt = f (B.Bind (id, B.Abbr u, tt)) in
+ let f cc = type_of f g cc t in
+ let f u = R.push f c (B.Abbr u) in
+ let f uu = match u with
+ | B.Cast _ -> f u
+ | _ -> f (B.Cast (uu, u))
in
- let f uu cc = type_of (f uu) g cc t in
- let f uu = R.push (f uu) c b u in
type_of f g c u
- | B.Appl (v, t) ->
+ | B.Bind (id, B.Abst u, t) ->
+ let f tt = f (B.Bind (id, B.Abst u, tt)) in
+ let f cc = type_of f g cc t in
+ let f _ = R.push f c (B.Abst u) in
+ type_of f g c u
+ | B.Bind (id, B.Void, t) ->
+ let f tt = f (B.Bind (id, B.Void, tt)) in
+ let f cc = type_of f g cc t in
+ R.push f c B.Void
+ | B.Appl (v, t) ->
let f tt cc = function
- | R.Sort _ -> error "appl"
+ | R.Sort _ -> error1 "not a function" c t
| R.Abst w ->
- let f b = if b then f (B.Appl (v, tt)) else error "appl_cast" in
- type_of (R.are_convertible f cc w) g c v
+ let f b =
+ if b then f (B.Appl (v, tt)) else
+ error2 "the term" c v "must be of type" cc w
+ in
+ type_of (are_convertible f cc w) g c v
in
let f tt = R.ho_whd (f tt) c t in
type_of f g c t
- | B.Cast (u, t) ->
- let f b = if b then f u else error "cast" in
- let f _ = type_of (R.are_convertible f c u) g c t in
+ | B.Cast (u, t) ->
+ let f b =
+ if b then f u else
+ error2 "the term" c t "must be of type" c u
+ in
+ let f _ = type_of (are_convertible f c u) g c t in
type_of f g c u