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_______________________________________________________________ *)
16 module E = BrgEnvironment
17 module R = BrgReduction
19 exception TypeError of B.message
21 (* Internal functions *******************************************************)
26 raise (TypeError (L.ct_items1 s c t))
28 let error2 s1 c1 t1 s2 c2 t2 =
29 raise (TypeError (L.ct_items2 s1 c1 t1 s2 c2 t2))
31 (* Interface functions ******************************************************)
33 let rec type_of f g c x =
34 L.log O.specs level (L.ct_items1 "now checking" c x);
37 let f h = f (B.Sort h) in H.apply f g h
40 | Some (_, B.Abst w) -> f w
41 | Some (_, B.Abbr (B.Cast (w, v))) -> f w
42 | Some (_, B.Abbr _) -> assert false
44 error1 "reference to excluded variable" c x
46 error1 "variable not found" c x
51 | _, _, B.Abst w -> f w
52 | _, _, B.Abbr (B.Cast (w, v)) -> f w
53 | _, _, B.Abbr _ -> assert false
55 error1 "reference to excluded object" c x
58 | B.Bind (id, B.Abbr u, t) ->
59 let f tt = f (B.Bind (id, B.Abbr u, tt)) in
60 let f cc = type_of f g cc t in
61 let f u = B.push f c id (B.Abbr u) in
62 let f uu = match u with
64 | _ -> f (B.Cast (uu, u))
67 | B.Bind (id, B.Abst u, t) ->
68 let f tt = f (B.Bind (id, B.Abst u, tt)) in
69 let f cc = type_of f g cc t in
70 let f _ = B.push f c id (B.Abst u) in
72 | B.Bind (id, B.Void, t) ->
73 let f tt = f (B.Bind (id, B.Void, tt)) in
74 let f cc = type_of f g cc t in
77 let f tt cc = function
78 | R.Sort _ -> error1 "not a function" c t
80 L.log O.specs (succ level) (L.ct_items1 "Just scanned" cc w);
82 if b then f (B.Appl (v, tt)) else
83 error2 "the term" c v "must be of type" cc w
85 type_of (R.are_convertible f cc w) g c v
87 let f tt = R.ho_whd (f tt) c t in
92 error2 "the term" c t "must be of type" c u
94 let f _ = type_of (R.are_convertible f c u) g c t in