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 *)
18 type attr = Name of bool * id (* real?, name *)
19 | Apix of int (* additional position index *)
21 type attrs = attr list
23 type bind = Void of attrs (* attrs *)
24 | Abst of attrs * term (* attrs, type *)
25 | Abbr of attrs * term (* attrs, body *)
27 and term = Sort of attrs * int (* attrs, hierarchy index *)
28 | LRef of attrs * int (* attrs, position index *)
29 | GRef of attrs * uri (* attrs, reference *)
30 | Cast of attrs * term * term (* attrs, type, term *)
31 | Appl of attrs * term * term (* attrs, argument, function *)
32 | Bind of bind * term (* binder, scope *)
34 type entry = bind Unit.entry (* age, uri, binder *)
36 type unit = bind Unit.unit
39 (* Cons: tail, relative local environment, binder *)
40 | Cons of lenv * lenv option * bind
42 (* Currified constructors ***************************************************)
44 let abst a w = Abst (a, w)
46 let abbr a v = Abbr (a, v)
48 let lref a i = LRef (a, i)
50 let cast a u t = Cast (a, u, t)
52 let appl a u t = Appl (a, u, t)
54 let bind b t = Bind (b, t)
56 let bind_abst a u t = Bind (Abst (a, u), t)
58 let bind_abbr a v t = Bind (Abbr (a, v), t)
60 (* local environment handling functions *************************************)
65 let es = Cons (es, c, b) in f es
68 let rec aux j = function
70 | Cons (tl, None, b) when j = 0 -> f tl b
71 | Cons (_, Some c, b) when j = 0 -> f c b
72 | Cons (tl, _, _) -> aux (pred j) tl
76 let rec rev_iter f map = function
78 | Cons (tl, None, b) ->
79 let f _ = map f tl b in rev_iter f map tl
80 | Cons (tl, Some c, b) ->
81 let f _ = map f c b in rev_iter f map tl
83 let rec fold_left f map x = function
86 let f x = fold_left f map x tl in
89 let rec name err f = function
91 | Name (r, n) :: _ -> f n r
92 | _ :: tl -> name err f tl
94 let rec apix err f = function
97 | _ :: tl -> apix err f tl