(* ||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 B = Brg module E = BrgEnvironment module R = BrgReduction exception TypeError of string Lazy.t (* Internal functions *******************************************************) let error msg = raise (TypeError (lazy msg)) (* Interface functions ******************************************************) let rec type_of f g c = function | 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, _ -> error "lref" 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, _ -> error "gref" in E.get_obj f uri | B.Bind (id, b, u, t) -> let f uu tt = match b, t with | B.Abst, _ | B.Abbr, B.Cast _ -> f (B.Bind (id, b, u, tt)) | _ -> f (B.Bind (id, b, B.Cast (uu, u), tt)) in let f uu cc = type_of (f uu) g cc t in let f uu = R.push (f uu) c b u in type_of f g c u | B.Appl (v, t) -> let f tt cc = function | R.Sort _ -> error "appl" | R.Abst w -> let f b = if b then f (B.Appl (v, tt)) else error "appl_cast" in type_of (R.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 error "cast" in let f _ = type_of (R.are_convertible f c u) g c t in type_of f g c u