2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
15 module E = BrgEnvironment
16 module R = BrgReduction
18 exception TypeError of B.message
20 (* Internal functions *******************************************************)
25 raise (TypeError (L.ct_items1 s c t))
27 let error2 s1 c1 t1 s2 c2 t2 =
28 raise (TypeError (L.ct_items2 s1 c1 t1 s2 c2 t2))
30 (* Interface functions ******************************************************)
32 let rec type_of f g c x =
33 L.log O.specs level (L.ct_items1 "now checking" c x);
35 | B.Sort h -> f (B.Sort (g h))
38 | Some (_, B.Abst w) -> f w
39 | Some (_, B.Abbr (B.Cast (w, v))) -> f w
40 | Some (_, B.Abbr _) -> assert false
42 error1 "reference to excluded variable" c x
44 error1 "variable not found" c x
49 | _, _, B.Abst w -> f w
50 | _, _, B.Abbr (B.Cast (w, v)) -> f w
51 | _, _, B.Abbr _ -> assert false
53 error1 "reference to excluded object" c x
56 | B.Bind (id, B.Abbr u, t) ->
57 let f tt = f (B.Bind (id, B.Abbr u, tt)) in
58 let f cc = type_of f g cc t in
59 let f u = B.push f c id (B.Abbr u) in
60 let f uu = match u with
62 | _ -> f (B.Cast (uu, u))
65 | B.Bind (id, B.Abst u, t) ->
66 let f tt = f (B.Bind (id, B.Abst u, tt)) in
67 let f cc = type_of f g cc t in
68 let f _ = B.push f c id (B.Abst u) in
70 | B.Bind (id, B.Void, t) ->
71 let f tt = f (B.Bind (id, B.Void, tt)) in
72 let f cc = type_of f g cc t in
75 let f tt cc = function
76 | R.Sort _ -> error1 "not a function" c t
78 L.log O.specs (succ level) (L.ct_items1 "Just scanned" cc w);
80 if b then f (B.Appl (v, tt)) else
81 error2 "the term" c v "must be of type" cc w
83 type_of (R.are_convertible f cc w) g c v
85 let f tt = R.ho_whd (f tt) c t in
90 error2 "the term" c t "must be of type" c u
92 let f _ = type_of (R.are_convertible f c u) g c t in