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 b_attrs = E.bind_attrs
25 type bind = Abst of bool * N.layer * term (* x-reduced?, layer, type *)
26 | Abbr of term (* body *)
29 and term = TSort of int (* hierarchy index *)
30 | TLRef of n_attrs * int (* attrs, position indexe *)
31 | TGRef of n_attrs * uri (* attrs, reference *)
32 | TCast of term * term (* domain, element *)
33 | TAppl of bool * term * term (* extended?, argument, function *)
34 | TBind of b_attrs * bind * term (* attrs, binder, scope *)
35 | TProj of lenv * term (* closure, member *)
37 and lenv = ESort (* top *)
38 | EBind of lenv * n_attrs * b_attrs * bind (* environment, attrs, binder *)
39 | EAppl of lenv * bool * term (* environment, extended?, argument *)
40 | EProj of lenv * lenv (* environment, closure *)
42 type entity = term E.entity
44 (* helpers ******************************************************************)
46 let empty_lenv = ESort
48 let push_bind f a y b lenv = f (EBind (lenv, a, y, b))
50 let push_appl f x t lenv = f (EAppl (lenv, x, t))
52 let push_proj f e lenv = f (EProj (lenv, e))
54 let add_bind f y b t = f (TBind (y, b, t))
56 let add_appl f x v t = f (TAppl (x, v, t))
58 let add_proj f e t = f (TProj (e, t))
60 let rec shift f c t = match c with
62 | EBind (e, _, y, b) -> add_bind (shift f e) y b t
63 | EAppl (e, x, v) -> add_appl (shift f e) x v t
64 | EProj (e, d) -> add_proj (shift f e) d t
66 let rec append f c = function
68 | EBind (e, a, y, b) -> append (push_bind f a y b) c e
69 | EAppl (e, x, t) -> append (push_appl f x t) c e
70 | EProj (e, d) -> append (push_proj f d) c e
72 let resolve_lref err f id lenv =
73 let rec aux i = function
75 | EAppl (tl, _, _) -> aux i tl
76 | EBind (tl, a, y, _) ->
77 let f id0 _ = if id0 = id then f a y i else aux (succ i) tl in
78 let err () = aux (succ i) tl in
80 | EProj (tl, d) -> append (aux i) tl d
84 let rec get_name err f i = function
86 | EAppl (tl, _, _) -> get_name err f i tl
87 | EBind (_, _, y, _) when i = 0 ->
90 | EBind (tl, _, _, _) -> get_name err f (pred i) tl
92 let err i = get_name err f i tl in
95 let rec get e i = match e with
96 | ESort -> ESort, E.empty_node, E.empty_bind, Void
97 | EBind (e, a, y, b) when i = 0 -> e, a, y, b
98 | EBind (e, _, _, _) -> get e (pred i)
99 | EAppl (e, _, _) -> get e i
100 | EProj (e, d) -> get (append C.start e d) i
102 let rec sub_list_strict f e l = match e, l with
104 | EBind (e, _, _, Abst _), _ :: tl -> sub_list_strict f e tl
107 let rec fold_names f map x = function
109 | EBind (e, _, {E.b_name = Some n}, Abst _) -> fold_names f map (map x n) e
112 let rec mem err f e y0 = match e with
114 | EBind (e, _, y, _) ->
115 if y.E.b_name = y0.E.b_name then f () else mem err f e y0
116 | EAppl (e, _, _) -> mem err f e y0
118 let err () = mem err f e y0 in mem err f d y0
120 let set_layer f n0 e =
121 let rec aux f = function
123 | EBind (e, a, y, Abst (r, n, w)) -> aux (push_bind f a y (Abst (r, n0, w))) e
124 | EBind (e, a, y, b) -> aux (push_bind f a y b) e
125 | EAppl (e, x, v) -> aux (push_appl f x v) e
126 | EProj (e, d) -> let f d = aux (push_proj f d) e in aux f d
130 let set_attrs f y0 e =
131 let rec aux f = function
133 | EBind (e, a, y, b) ->
134 let y = E.compose y y0 in
135 aux (push_bind f a y b) e
137 aux (push_appl f x v) e
139 let f d = aux (push_proj f d) e in