(* ||M|| This file is part of HELM, an Hypertextual, Electronic ||A|| Library of Mathematics, developed at the Computer Science ||T|| Department, University of Bologna, Italy. ||I|| ||T|| HELM is free software; you can redistribute it and/or ||A|| modify it under the terms of the GNU General Public License \ / version 2 or (at your option) any later version. \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) module L = Log module B = Brg module O = BrgOutput module E = BrgEnvironment module R = BrgReduction exception TypeError of (R.context, B.term) Log.item list (* Internal functions *******************************************************) let error1 s c t = raise (TypeError (L.ct_items1 s c t)) let error2 s1 c1 t1 s2 c2 t2 = raise (TypeError (L.ct_items2 s1 c1 t1 s2 c2 t2)) let are_convertible f c t1 t2 = L.log O.specs 4 (L.ct_items2 "Now converting" c t1 "and" c t2); R.are_convertible f c t1 t2 (* Interface functions ******************************************************) let rec type_of f g c x = L.log O.specs 5 (L.ct_items1 "now checking" c x); match x with | B.Sort h -> f (B.Sort (g h)) | B.LRef i -> let f = function | B.Abst w -> f w | B.Abbr (B.Cast (w, v)) -> f w | B.Abbr _ -> assert false | B.Void -> assert false in R.get f c i | B.GRef uri -> let f = function | _, _, B.Abst w -> f w | _, _, B.Abbr (B.Cast (w, v)) -> f w | _, _, B.Abbr _ -> assert false | _, _, B.Void -> assert false in E.get_obj f uri | B.Bind (id, B.Abbr u, t) -> let f tt = f (B.Bind (id, B.Abbr u, tt)) in let f cc = type_of f g cc t in let f u = R.push f c (B.Abbr u) in let f uu = match u with | B.Cast _ -> f u | _ -> f (B.Cast (uu, u)) in type_of f g c u | B.Bind (id, B.Abst u, t) -> let f tt = f (B.Bind (id, B.Abst u, tt)) in let f cc = type_of f g cc t in let f _ = R.push f c (B.Abst u) in type_of f g c u | B.Bind (id, B.Void, t) -> let f tt = f (B.Bind (id, B.Void, tt)) in let f cc = type_of f g cc t in R.push f c B.Void | B.Appl (v, t) -> let f tt cc = function | R.Sort _ -> error1 "not a function" c t | R.Abst w -> let f b = if b then f (B.Appl (v, tt)) else error2 "the term" c v "must be of type" cc w in type_of (are_convertible f cc w) g c v in let f tt = R.ho_whd (f tt) c t in type_of f g c t | B.Cast (u, t) -> let f b = if b then f u else error2 "the term" c t "must be of type" c u in let f _ = type_of (are_convertible f c u) g c t in type_of f g c u