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_______________________________________________________________ *)
20 module E = BagEnvironment
21 module R = BagReduction
23 exception TypeError of B.message
25 (* Internal functions *******************************************************)
30 let sc, st = s ^ " in the envireonment", "the term" in
31 L.log O.specs level (L.et_items1 sc c st t)
34 let sc = "In the envireonment" in
35 raise (TypeError (L.et_items1 sc c st t))
37 let error3 c t1 t2 t3 =
38 let sc, st1, st2, st3 =
39 "In the envireonment", "the term", "is of type", "but must be of type"
41 raise (TypeError (L.et_items3 sc c st1 t1 st2 t2 st3 t3))
44 let map t v = B.Appl (v, t) in
45 List.fold_left map (B.GRef u) l
47 (* Interface functions ******************************************************)
49 let rec b_type_of f ~si g c x =
50 (* L.warn "Entering T.b_type_of"; *)
51 log1 "Now checking" c x;
54 let f h = f x (B.Sort h) in H.apply f g h
57 | Some (_, B.Abst w) -> f x w
58 | Some (_, B.Abbr (B.Cast (w, v))) -> f x w
59 | Some (_, B.Abbr _) -> assert false
61 error1 "reference to excluded variable" c x
63 error1 "variable not found" c x
68 | _, _, Y.Abst w -> f x w
69 | _, _, Y.Abbr (B.Cast (w, v)) -> f x w
70 | _, _, Y.Abbr _ -> assert false
73 | B.Bind (l, id, B.Abbr v, t) ->
75 f (S.sh2 v xv t xt x (B.bind_abbr l id)) (B.bind_abbr l id xv tt)
77 let f xv cc = b_type_of (f xv) ~si g cc t in
78 let f xv = B.push "type abbr" (f xv) c l id (B.Abbr xv) in
79 let f xv vv = match xv with
81 | _ -> f (B.Cast (vv, xv))
84 | B.Bind (l, id, B.Abst u, t) ->
86 f (S.sh2 u xu t xt x (B.bind_abst l id)) (B.bind_abst l id xu tt)
88 let f xu cc = b_type_of (f xu) ~si g cc t in
89 let f xu _ = B.push "type abst" (f xu) c l id (B.Abst xu) in
91 | B.Bind (l, id, B.Void, t) ->
93 f (S.sh1 t xt x (B.bind l id B.Void)) (B.bind l id B.Void tt)
95 let f cc = b_type_of f ~si g cc t in
96 B.push "type void" f c l id B.Void
98 let f xv vv xt tt = function
101 L.log O.specs (succ level) (L.t_items1 "Just scanned" c w);
102 L.unbox (succ level);
104 (* L.warn (Printf.sprintf "Convertible: %b" a); *)
105 if a then f (S.sh2 v xv t xt x B.appl) (B.appl xv tt)
106 else error3 c xv vv w
108 R.are_convertible f ~si c w vv
110 error1 "not a function" c xt
112 let f xv vv xt tt = R.ho_whd (f xv vv xt tt) c tt in
113 let f xv vv = b_type_of (f xv vv) ~si g c t in
117 (* L.warn (Printf.sprintf "Convertible: %b" a); *)
118 if a then f (S.sh2 u xu t xt x B.cast) xu else error3 c xt tt xu
120 let f xu xt tt = R.are_convertible (f xu xt tt) ~si c xu tt in
121 let f xu _ = b_type_of (f xu) ~si g c t in
124 and type_of f ?(si=false) g c x =
125 let f t u = L.unbox level; f t u in
126 L.box level; b_type_of f ~si g c x