]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/basic_rg/brg.ml
e6ac94e5bd8f4265ea05a0afe7718bab1d9f211e
[helm.git] / helm / software / helena / src / basic_rg / brg.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 (* kernel version: basic, relative, global *)
13 (* note          : ufficial basic \lambda\delta version 3 *) 
14
15 module N = Layer
16 module E = Entity
17
18 type uri = E.uri
19 type n_attrs = E.node_attrs
20 type b_attrs = E.bind_attrs
21
22 (* x-reduced abstractions are output by RTM only *)
23 type bind = Void                          (*                         *)
24           | Abst of bool * N.layer * term (* x-reduced?, layer, type *)
25           | Abbr of term                  (* body                    *)
26
27 and term = Sort of int                    (* hierarchy index *)
28          | LRef of n_attrs * int          (* attrs, position index *)
29          | GRef of n_attrs * uri          (* attrs, reference *)
30          | Cast of term * term            (* type, term *)
31          | Appl of bool * term * term     (* extended?, argument, function *)
32          | Bind of b_attrs * bind * term  (* attrs, binder, scope *)
33
34 type entity = term E.entity (* attrs, uri, binder *)
35
36 type lenv = Null
37 (* Cons: tail, relative local environment, attrs, binder *) 
38           | Cons of lenv * lenv * n_attrs * b_attrs * bind 
39
40 type manager = (N.status -> entity -> bool) * (unit -> unit)
41
42 (* Currified constructors ***************************************************)
43
44 let abst r n w = Abst (r, n, w)
45
46 let abbr v = Abbr v
47
48 let lref a i = LRef (a, i)
49
50 let gref a u = GRef (a, u)
51
52 let cast u t = Cast (u, t)
53
54 let appl x u t = Appl (x, u, t)
55
56 let bind y b t = Bind (y, b, t)
57
58 let bind_abst r n y u t = Bind (y, Abst (r, n, u), t)
59
60 let bind_abbr y u t = Bind (y, Abbr u, t)
61
62 let bind_void y t = Bind (y, Void, t)
63
64 (* local environment handling functions *************************************)
65
66 let empty = Null
67
68 let push e c a y b = Cons (e, c, a, y, b)
69
70 let rec get e i = match e with
71    | Null                            -> empty, empty, E.empty_node, E.empty_bind, Void
72    | Cons (e, c, a, y, b) when i = 0 -> e, c, a, y, b
73    | Cons (e, _, _, _, _)            -> get e (pred i)
74
75 (* used in BrgOutput.pp_lenv *)
76 let rec fold_right f map e x = match e with   
77    | Null                 -> f x
78    | Cons (e, c, a, y, b) -> fold_right (map f c a y b) map e x
79
80 let rec mem err f e y0 = match e with
81    | Null                 -> err ()
82    | Cons (e, _, _, y, _) ->
83       if y.E.b_name = y0.E.b_name then f () else mem err f e y0