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: complete, relative, global *)
13 (* note : fragment of complete \lambda\delta serving as abstract layer *)
21 type attrs = E.node_attrs
23 type bind = Abst of N.layer * term (* layer, type *)
24 | Abbr of term (* body *)
27 and term = TSort of attrs * int (* attrs, hierarchy index *)
28 | TLRef of attrs * int (* attrs, position indexe *)
29 | TGRef of attrs * uri (* attrs, reference *)
30 | TCast of attrs * term * term (* attrs, domain, element *)
31 | TAppl of attrs * term * term (* attrs, argument, function *)
32 | TBind of attrs * bind * term (* attrs, binder, scope *)
33 | TProj of attrs * lenv * term (* attrs, closure, member *)
35 and lenv = ESort (* top *)
36 | EBind of lenv * attrs * bind (* environment, attrs, binder *)
37 | EAppl of lenv * attrs * term (* environment, attrs, argument *)
38 | EProj of lenv * attrs * lenv (* environment, attrs, closure *)
40 type entity = term E.entity
42 (* helpers ******************************************************************)
44 let empty_lenv = ESort
46 let push_bind f a b lenv = f (EBind (lenv, a, b))
48 let push_appl f a t lenv = f (EAppl (lenv, a, t))
50 let push_proj f a e lenv = f (EProj (lenv, a, e))
52 let add_bind f a b t = f (TBind (a, b, t))
54 let add_appl f a v t = f (TAppl (a, v, t))
56 let add_proj f a e t = f (TProj (a, e, t))
58 let rec shift f c t = match c with
60 | EBind (e, a, b) -> add_bind (shift f e) a b t
61 | EAppl (e, a, v) -> add_appl (shift f e) a v t
62 | EProj (e, a, d) -> add_proj (shift f e) a d t
64 let rec append f c = function
66 | EBind (e, a, b) -> append (push_bind f a b) c e
67 | EAppl (e, a, t) -> append (push_appl f a t) c e
68 | EProj (e, a, d) -> append (push_proj f a d) c e
70 let resolve_lref err f id lenv =
71 let rec aux i = function
73 | EAppl (tl, _, _) -> aux i tl
75 let f id0 _ = if id0 = id then f a i else aux (succ i) tl in
76 let err () = aux (succ i) tl in
78 | EProj (tl, _, d) -> append (aux i) tl d
82 let rec get_name err f i = function
84 | EAppl (tl, _, _) -> get_name err f i tl
85 | EBind (_, a, _) when i = 0 ->
88 | EBind (tl, _, _) -> get_name err f (pred i) tl
90 let err i = get_name err f i tl in
93 let rec get e i = match e with
94 | ESort -> ESort, E.empty_node, Void
95 | EBind (e, a, b) when i = 0 -> e, a, b
96 | EBind (e, _, _) -> get e (pred i)
97 | EAppl (e, _, _) -> get e i
98 | EProj (e, _, d) -> get (append C.start e d) i
100 let rec sub_list_strict f e l = match e, l with
102 | EBind (e, _, Abst _), _ :: tl -> sub_list_strict f e tl
105 let rec fold_names f map x = function
107 | EBind (e, {E.n_name = Some n}, Abst _) -> fold_names f map (map x n) e
110 let rec mem err f e b = match e with
113 if a.E.n_name = b.E.n_name then f () else mem err f e b
114 | EAppl (e, _, _) -> mem err f e b
116 let err () = mem err f e b in mem err f d b
119 let rec aux f = function
121 | EBind (e, a, Abst (n, w)) -> aux (push_bind f a (Abst (n0, w))) e
122 | EBind (e, a, b) -> aux (push_bind f a b) e
123 | EAppl (e, a, v) -> aux (push_appl f a v) e
124 | EProj (e, a, d) -> let f d = aux (push_proj f a d) e in aux f d