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_______________________________________________________________ *)
19 module E = BrgEnvironment
20 module R = BrgReduction
22 exception TypeError of B.message
24 (* Internal functions *******************************************************)
29 raise (TypeError (L.ct_items1 s c t))
31 let error2 s1 c1 t1 s2 c2 t2 =
32 raise (TypeError (L.ct_items2 s1 c1 t1 s2 c2 t2))
35 let map t v = B.Appl (v, t) in
36 List.fold_left map (B.GRef u) l
38 (* Interface functions ******************************************************)
40 let rec b_type_of f g c x =
41 L.log O.specs level (L.ct_items1 "Now checking" c x);
44 let f h = f x (B.Sort h) in H.apply f g h
47 | Some (_, B.Abst w) -> f x w
48 | Some (_, B.Abbr (B.Cast (w, v))) -> f x w
49 | Some (_, B.Abbr _) -> assert false
51 error1 "reference to excluded variable" c x
53 error1 "variable not found" c x
58 | _, _, B.Abst w -> f x w
59 | _, _, B.Abbr (B.Cast (w, v)) -> f x w
60 | _, _, B.Abbr _ -> assert false
62 error1 "reference to excluded object" c x
65 | B.Bind (id, B.Abbr v, t) ->
67 f (S.sh2 v xv t xt x (B.bind_abbr id)) (B.bind_abbr id xv tt)
69 let f xv cc = b_type_of (f xv) g cc t in
70 let f xv = B.push (f xv) c id (B.Abbr xv) in
71 let f xv vv = match xv with
73 | _ -> f (B.Cast (vv, xv))
76 | B.Bind (id, B.Abst u, t) ->
78 f (S.sh2 u xu t xt x (B.bind_abst id)) (B.bind_abst id xu tt)
80 let f xu cc = b_type_of (f xu) g cc t in
81 let f xu _ = B.push (f xu) c id (B.Abst xu) in
83 | B.Bind (id, B.Void, t) ->
85 f (S.sh1 t xt x (B.bind id B.Void)) (B.bind id B.Void tt)
87 let f cc = b_type_of f g cc t in
90 let h xv vv xt tt cc = function
91 | R.Sort _ -> error1 "not a function" c xt
93 L.log O.specs (succ level) (L.ct_items1 "Just scanned" cc w);
95 if b then f (S.sh2 v xv t xt x B.appl) (B.appl xv tt) else
96 error2 "the term" cc xv "must be of type" cc w
98 R.are_convertible f cc w vv
100 let f xv vv xt = function
101 (* inserting a missing "modus ponens" *)
102 | B.Appl (y2, B.Appl (y1, B.GRef u)) when U.eq u I.imp ->
103 b_type_of f g c (mk_gref I.mp [y1; y2; xv; xt])
104 | tt -> R.ho_whd (h xv vv xt tt) c tt
106 let f xv vv = b_type_of (f xv vv) g c t in
110 if b then f (S.sh2 u xu t xt x B.cast) xu else
111 error2 "the term" c xt "must be of type" c xu
113 let f xu xt tt = R.are_convertible (f xu xt) c xu tt in
114 let f xu _ = b_type_of (f xu) g c t in
117 and type_of f g c x =
118 let f t u = L.unbox (); f t u in
119 L.box (); b_type_of f g c x