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 n_attrs = E.node_attrs
22 type a_attrs = E.appl_attrs
23 type b_attrs = E.bind_attrs
26 type bind = Abst of bool * N.layer * term (* x-reduced?, layer, type *)
27 | Abbr of term (* body *)
30 and term = TSort of int (* hierarchy index *)
31 | TLRef of n_attrs * int (* attrs, position indexe *)
32 | TGRef of n_attrs * uri (* attrs, reference *)
33 | TCast of term * term (* domain, element *)
34 | TAppl of a_attrs * term * term (* attrs, argument, function *)
35 | TBind of b_attrs * bind * term (* attrs, binder, scope *)
36 | TProj of lenv * term (* closure, member *)
38 and lenv = ESort (* top *)
39 | EBind of lenv * n_attrs * b_attrs * bind (* environment, attrs, binder *)
40 | EAppl of lenv * a_attrs * term (* environment, attrs, argument *)
41 | EProj of lenv * lenv (* environment, closure *)
43 type entity = term E.entity
45 (* helpers ******************************************************************)
47 let empty_lenv = ESort
49 let push_bind f a y b lenv = f (EBind (lenv, a, y, b))
51 let push_appl f a t lenv = f (EAppl (lenv, a, t))
53 let push_proj f e lenv = f (EProj (lenv, e))
55 let add_bind f y b t = f (TBind (y, b, t))
57 let add_appl f a v t = f (TAppl (a, v, t))
59 let add_proj f e t = f (TProj (e, t))
61 let rec shift f c t = match c with
63 | EBind (e, _, a, b) -> add_bind (shift f e) a b t
64 | EAppl (e, a, v) -> add_appl (shift f e) a v t
65 | EProj (e, d) -> add_proj (shift f e) d t
67 let rec append f c = function
69 | EBind (e, y, a, b) -> append (push_bind f y a b) c e
70 | EAppl (e, a, t) -> append (push_appl f a t) c e
71 | EProj (e, d) -> append (push_proj f d) c e
73 let resolve_lref err f id lenv =
74 let rec aux i = function
76 | EAppl (tl, _, _) -> aux i tl
77 | EBind (tl, y, a, _) ->
78 let f id0 _ = if id0 = id then f y a i else aux (succ i) tl in
79 let err () = aux (succ i) tl in
81 | EProj (tl, d) -> append (aux i) tl d
85 let rec get_name err f i = function
87 | EAppl (tl, _, _) -> get_name err f i tl
88 | EBind (_, _, a, _) when i = 0 ->
91 | EBind (tl, _, _, _) -> get_name err f (pred i) tl
93 let err i = get_name err f i tl in
96 let rec get e i = match e with
97 | ESort -> ESort, E.empty_node, E.empty_bind, Void
98 | EBind (e, y, a, b) when i = 0 -> e, y, a, b
99 | EBind (e, _, _, _) -> get e (pred i)
100 | EAppl (e, _, _) -> get e i
101 | EProj (e, d) -> get (append C.start e d) i
103 let rec sub_list_strict f e l = match e, l with
105 | EBind (e, _, _, Abst _), _ :: tl -> sub_list_strict f e tl
108 let rec fold_names f map x = function
110 | EBind (e, _, {E.b_name = Some n}, Abst _) -> fold_names f map (map x n) e
113 let rec mem err f e a0 = match e with
115 | EBind (e, _, a, _) ->
116 if a.E.b_name = a0.E.b_name then f () else mem err f e a0
117 | EAppl (e, _, _) -> mem err f e a0
119 let err () = mem err f e a0 in mem err f d a0
121 let set_layer f n0 e =
122 let rec aux f = function
124 | EBind (e, y, a, Abst (r, n, w)) -> aux (push_bind f y a (Abst (r, n0, w))) e
125 | EBind (e, y, a, b) -> aux (push_bind f y a b) e
126 | EAppl (e, a, v) -> aux (push_appl f a v) e
127 | EProj (e, d) -> let f d = aux (push_proj f d) e in aux f d
131 let set_attrs f a0 e =
132 let rec aux f = function
134 | EBind (e, y, a, b) ->
135 let a = E.compose a a0 in
136 aux (push_bind f y a b) e
138 aux (push_appl f a v) e
140 let f d = aux (push_proj f d) e in