]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/basic_rg/brg.ml
new kernel basic_rg: implements ufficial lambda-delta with de Bruijn indexes
[helm.git] / helm / software / lambda-delta / 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 = NUri.uri
16 type id = Aut.id
17
18 type bind = Void         (* exclusion *)
19           | Abst of term (* abstraction *)
20           | Abbr of term (* abbreviation *)
21
22 and term = Sort of attrs * int         (* attrs, hierarchy index *)
23          | LRef of attrs * int         (* attrs, position index *)
24          | GRef of attrs * uri         (* attrs, reference *)
25          | Cast of attrs * term * term (* attrs, type, term *)
26          | Appl of attrs * term * term (* attrs, argument, function *)
27          | Bind of attrs * bind * term (* attrs, binder, scope *)
28
29 and attr = Name of bool * id   (* real?, name *)
30          | Entry of int * bind (* age, binder *)
31
32 and attrs = attr list
33
34 type obj = int * uri * bind (* age, uri, binder, contents *)
35
36 type item = obj option
37
38 type context = (attrs * bind) list (* attrs, binder *) 
39
40 type message = (context, term) Log.item list
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 (* context handling functions ***********************************************)
61
62 let empty_context = []
63
64 let push f es a b =
65    let c = (a, b) :: es in f c
66
67 let append f es1 es2 = 
68    f (List.append es2 es1)
69
70 let map f map es =
71    Cps.list_map f map es
72
73 let contents f es = f es
74
75 let get f es i =
76    let rec aux e i = function
77       | []       -> f e None
78       | hd :: tl -> 
79          if i = 0 then f e (Some hd) else 
80          let e = match hd with _, Abst _ -> succ e | _ -> e in  
81          aux e (pred i) tl
82    in
83    aux 0 i es
84
85 let rec name f = function
86    | []               -> f None
87    | Name (r, n) :: _ -> f (Some (r, n))
88    | _ :: tl          -> name f tl