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_______________________________________________________________ *)
21 module ZE = BagEnvironment
22 module ZR = BagReduction
26 (* Internal functions *******************************************************)
31 let s1, s2 = s ^ " in the envireonment", "the term" in
32 L.log st ZO.specs (pred level) (L.et_items1 s1 c s2 t)
34 let error1 err st c t =
35 let sc = "In the envireonment" in
36 err (L.et_items1 sc c st t)
38 let error3 err c t1 t2 t3 =
39 let sc, st1, st2, st3 =
40 "In the envireonment", "the term", "is of type", "but must be of type"
42 err (L.et_items3 sc c st1 t1 st2 t2 st3 t3)
45 let map t v = Z.Appl (v, t) in
46 List.fold_left map (Z.GRef u) l
48 let rec b_type_of err f st c x =
49 (* L.warn "Entering T.b_type_of"; *)
51 if !G.ct >= level then log1 st "Now checking" c x
55 let h = H.apply h in f x (Z.Sort h)
57 let err0 () = error1 err "variable not found" c x in
60 | Z.Abbr (Z.Cast (w, v)) -> f x w
61 | Z.Abbr _ -> assert false
62 | Z.Void -> error1 err "reference to excluded variable" c x
67 | _, _, _, E.Abst (_, w) -> f x w
68 | _, _, _, E.Abbr (_, Z.Cast (w, v)) -> f x w
69 | _, _, _, E.Abbr _ -> assert false
70 | _, _, _, E.Void -> assert false
73 | Z.Bind (y, l, Z.Abbr v, t) ->
75 f (S.sh2 v xv t xt x (Z.bind_abbr y l)) (Z.bind_abbr y l xv tt)
77 let f xv cc = b_type_of err (f xv) st cc t in
78 let f xv = Z.push "type abbr" (f xv) c y l (Z.Abbr xv) in
79 let f xv vv = match xv with
81 | _ -> f (Z.Cast (vv, xv))
84 | Z.Bind (y, l, Z.Abst u, t) ->
86 f (S.sh2 u xu t xt x (Z.bind_abst y l)) (Z.bind_abst y l xu tt)
88 let f xu cc = b_type_of err (f xu) st cc t in
89 let f xu _ = Z.push "type abst" (f xu) c y l (Z.Abst xu) in
91 | Z.Bind (y, l, Z.Void, t) ->
93 f (S.sh1 t xt x (Z.bind y l Z.Void)) (Z.bind y l Z.Void tt)
95 let f cc = b_type_of err f st cc t in
96 Z.push "type void" f c y l Z.Void
98 let f xv vv xt tt = function
101 if !G.ct > level then L.log st ZO.specs level (L.t_items1 "Just scanned" c w)
104 (* L.warn (Printf.sprintf "Convertible: %b" a); *)
105 if a then f (S.sh2 v xv t xt x Z.appl) (Z.appl xv tt)
106 else error3 err c xv vv w
108 ZR.are_convertible f st c w vv
110 error1 err "not a function" c xt
112 let f xv vv xt tt = ZR.ho_whd (f xv vv xt tt) st c tt in
113 let f xv vv = b_type_of err (f xv vv) st c t in
117 (* L.warn (Printf.sprintf "Convertible: %b" a); *)
118 if a then f (S.sh2 u xu t xt x Z.cast) xu else error3 err c xt tt xu
120 let f xu xt tt = ZR.are_convertible (f xu xt tt) st c xu tt in
121 let f xu _ = b_type_of err (f xu) st c t in
124 (* Interface functions ******************************************************)
126 and type_of err f st c x = b_type_of err f st c x