]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/basic_ag/bag.ml
new kernel basic_ag (with absolute local references)
[helm.git] / helm / software / lambda-delta / basic_ag / bag.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 type uri = NUri.uri
13 type id = Aut.id
14
15 type bind = Void         (* exclusion *)
16           | Abst of term (* abstraction *)
17           | Abbr of term (* abbreviation *)
18
19 and term = Sort of int                    (* hierarchy index *)
20          | LRef of int                    (* location *)
21          | GRef of uri                    (* reference *)
22          | Cast of term * term            (* type, term *)
23          | Appl of term * term            (* argument, function *)
24          | Bind of int * id * bind * term (* location, name, binder, scope *)
25
26 type obj = int * uri * bind (* age, uri, binder, contents *)
27
28 type item = obj option
29
30 type context = (int * id * bind) list (* location, name, binder *) 
31
32 type message = (context, term) Log.item list
33
34 (* Currified constructors ***************************************************)
35
36 let abst w = Abst w
37
38 let abbr v = Abbr v
39
40 let lref i = LRef i
41
42 let cast u t = Cast (u, t)
43
44 let appl u t = Appl (u, t)
45
46 let bind l id b t = Bind (l, id, b, t)
47
48 let bind_abst l id u t = Bind (l, id, Abst u, t)
49
50 let bind_abbr l id v t = Bind (l, id, Abbr v, t)
51
52 (* location handling functions **********************************************)
53
54 let location = ref 0
55
56 let new_location () = let loc = !location in incr location; loc
57
58 (* context handling functions ***********************************************)
59
60 let empty_context = []
61
62 let push f es l id b =
63    let c = (l, id, b) :: es in f c
64
65 let append f es1 es2 = 
66    f (List.append es2 es1)
67
68 let map f map es =
69    Cps.list_map f map es
70
71 let contents f es = f es
72
73 let get f es i =
74    let rec aux = function
75       | []               -> f None
76       | (l, id, b) :: tl -> if l = i then f (Some (id, b)) else aux tl
77    in
78    aux es