(* ||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_______________________________________________________________ *) (* kernel version: basic, absolute, global *) (* note : experimental *) module P = Marks module E = Entity type uri = E.uri type b_attrs = E.bind_attrs type bind = Void (* exclusion *) | Abst of term (* abstraction *) | Abbr of term (* abbreviation *) and term = Sort of int (* hierarchy index *) | LRef of P.mark (* location *) | GRef of uri (* reference *) | Cast of term * term (* domain, element *) | Appl of term * term (* argument, function *) | Bind of b_attrs * P.mark * bind * term (* name, location, binder, scope *) type entity = term E.entity (* attrs, uri, binder *) type lenv = (b_attrs * P.mark * bind) list (* name, location, binder *) type message = (lenv, term) Log.item list (* Currified constructors ***************************************************) let abst w = Abst w let abbr v = Abbr v let lref i = LRef i let cast u t = Cast (u, t) let appl u t = Appl (u, t) let bind y l b t = Bind (y, l, b, t) let bind_abst y l u t = Bind (y, l, Abst u, t) let bind_abbr y l v t = Bind (y, l, Abbr v, t) (* local environment handling functions *************************************) let empty_lenv = [] let push msg f es y l b = let rec does_not_occur loc = function | [] -> true | (_, l, _) :: _ when l = loc -> false | _ :: es -> does_not_occur l es in if not (does_not_occur l es) then failwith msg else let c = (y, l, b) :: es in f c let append f es1 es2 = f (List.append es2 es1) let map f map es = Cps.list_map f map es let contents f es = f es let get err f es i = let rec aux = function | [] -> err () | (y, l, b) :: tl -> if l = i then f y b else aux tl in aux es let nth err f loc e = let rec aux n = function | [] -> err loc | (_, l, _) :: _ when l = loc -> f n | _ :: e -> aux (succ n) e in aux 0 e