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