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_______________________________________________________________ *)
12 (* kernel version: basic, relative, global *)
13 (* note : ufficial basic lambda-delta *)
21 type bind = Void (* *)
22 | Abst of term (* type *)
23 | Abbr of term (* body *)
25 and term = Sort of attrs * int (* attrs, hierarchy index *)
26 | LRef of attrs * int (* attrs, position index *)
27 | GRef of attrs * uri (* attrs, reference *)
28 | Cast of attrs * term * term (* attrs, type, term *)
29 | Appl of attrs * term * term (* attrs, argument, function *)
30 | Bind of attrs * bind * term (* attrs, binder, scope *)
32 type entity = term E.entity (* attrs, uri, binder *)
35 (* Cons: tail, relative local environment, attrs, binder *)
36 | Cons of lenv * lenv * attrs * bind
38 (* helpers ******************************************************************)
40 let mk_uri si root s =
41 let kernel = if si then "brg-si" else "brg" in
42 String.concat "/" ["ld:"; kernel; root; s ^ ".ld"]
44 (* Currified constructors ***************************************************)
50 let lref a i = LRef (a, i)
52 let cast a u t = Cast (a, u, t)
54 let appl a u t = Appl (a, u, t)
56 let bind a b t = Bind (a, b, t)
58 let bind_abst a u t = Bind (a, Abst u, t)
60 let bind_abbr a v t = Bind (a, Abbr v, t)
62 let bind_void a t = Bind (a, Void, t)
64 (* local environment handling functions *************************************)
68 let push e c a b = Cons (e, c, a, b)
70 let rec get i = function
71 | Null -> Null, Null, [], Void
72 | Cons (e, c, a, b) when i = 0 -> e, c, a, b
73 | Cons (e, _, _, _) -> get (pred i) e
77 (* used in BrgOutput.pp_lenv *)
78 let rec fold_right f map e x = match e with
80 | Cons (e, c, a, b) -> fold_right (map f e c a b) map e x
82 (* used in MetaBrg.unwind_to_xlate_term *)
83 let rec fold_left map x = function
85 | Cons (e, _, a, b) -> fold_left map (map x a b) e