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