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 (R.context, B.term) Log.item list
20 (* Internal functions *******************************************************)
23 raise (TypeError (L.ct_items1 s c t))
25 let error2 s1 c1 t1 s2 c2 t2 =
26 raise (TypeError (L.ct_items2 s1 c1 t1 s2 c2 t2))
28 let are_convertible f c t1 t2 =
29 L.log O.specs 4 (L.ct_items2 "Now converting" c t1 "and" c t2);
30 R.are_convertible f c t1 t2
32 (* Interface functions ******************************************************)
34 let rec type_of f g c x =
35 L.log O.specs 5 (L.ct_items1 "now checking" c x);
37 | B.Sort h -> f (B.Sort (g h))
41 | B.Abbr (B.Cast (w, v)) -> f w
42 | B.Abbr _ -> assert false
43 | B.Void -> assert false
48 | _, _, B.Abst w -> f w
49 | _, _, B.Abbr (B.Cast (w, v)) -> f w
50 | _, _, B.Abbr _ -> assert false
51 | _, _, B.Void -> assert false
54 | B.Bind (id, B.Abbr u, t) ->
55 let f tt = f (B.Bind (id, B.Abbr u, tt)) in
56 let f cc = type_of f g cc t in
57 let f u = R.push f c (B.Abbr u) in
58 let f uu = match u with
60 | _ -> f (B.Cast (uu, u))
63 | B.Bind (id, B.Abst u, t) ->
64 let f tt = f (B.Bind (id, B.Abst u, tt)) in
65 let f cc = type_of f g cc t in
66 let f _ = R.push f c (B.Abst u) in
68 | B.Bind (id, B.Void, t) ->
69 let f tt = f (B.Bind (id, B.Void, tt)) in
70 let f cc = type_of f g cc t in
73 let f tt cc = function
74 | R.Sort _ -> error1 "not a function" c t
77 if b then f (B.Appl (v, tt)) else
78 error2 "the term" c v "must be of type" cc w
80 type_of (are_convertible f cc w) g c v
82 let f tt = R.ho_whd (f tt) c t in
87 error2 "the term" c t "must be of type" c u
89 let f _ = type_of (are_convertible f c u) g c t in