]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/components/basic_rg/brg.ml
refactoring: helena sources are now in a dedicated directory
[helm.git] / helm / software / lambda-delta / components / 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 type uri = Entity.uri
16 type id = Entity.id
17 type attrs = Entity.attrs
18
19 type bind = Void         (*      *)
20           | Abst of term (* type *)
21           | Abbr of term (* body *)
22
23 and term = Sort of attrs * int         (* attrs, hierarchy index *)
24          | LRef of attrs * int         (* attrs, position index *)
25          | GRef of attrs * uri         (* attrs, reference *)
26          | Cast of attrs * term * term (* attrs, type, term *)
27          | Appl of attrs * term * term (* attrs, argument, function *)
28          | Bind of attrs * bind * term (* attrs, binder, scope *)
29
30 type entity = term Entity.entity (* attrs, uri, binder *)
31
32 type lenv = Null
33 (* Cons: tail, relative local environment, attrs, binder *) 
34           | Cons of lenv * lenv * attrs * bind 
35
36 (* helpers ******************************************************************)
37
38 let mk_uri si root s =
39    let kernel = if si then "brg-si" else "brg" in
40    String.concat "/" ["ld:"; kernel; root; s ^ ".ld"]
41
42 (* Currified constructors ***************************************************)
43
44 let abst w = Abst w
45
46 let abbr v = Abbr v
47
48 let lref a i = LRef (a, i)
49
50 let cast a u t = Cast (a, u, t)
51
52 let appl a u t = Appl (a, u, t)
53
54 let bind a b t = Bind (a, b, t)
55
56 let bind_abst a u t = Bind (a, Abst u, t)
57
58 let bind_abbr a v t = Bind (a, Abbr v, t)
59
60 let bind_void a t = Bind (a, Void, t)
61
62 (* local environment handling functions *************************************)
63
64 let empty = Null
65
66 let push e c a b = Cons (e, c, a, b)
67
68 let rec get i = function
69    | Null                         -> Null, Null, [], Void
70    | Cons (e, c, a, b) when i = 0 -> e, c, a, b
71    | Cons (e, _, _, _)            -> get (pred i) e
72
73 let get e i = get i e
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, b) -> fold_right (map f e c a b) map e x
79
80 (* used in MetaBrg.unwind_to_xlate_term *)
81 let rec fold_left map x = function
82    | Null              -> x
83    | Cons (e, _, a, b) -> fold_left map (map x a b) e