]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/src/basic_ag/bag.ml
d3ac2c8ee544d22616ba96859df8ec353fde5822
[helm.git] / helm / software / lambda-delta / src / 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 (* kernel version: basic, absolute, global *)
13 (* note          : experimental *) 
14
15 module E = Entity
16
17 type uri = E.uri
18 type id = E.id
19
20 type bind = Void         (* exclusion *)
21           | Abst of term (* abstraction *)
22           | Abbr of term (* abbreviation *)
23
24 and term = Sort of int                    (* hierarchy index *)
25          | LRef of int                    (* location *)
26          | GRef of uri                    (* reference *)
27          | Cast of term * term            (* domain, element *)
28          | Appl of term * term            (* argument, function *)
29          | Bind of int * id * bind * term (* location, name, binder, scope *)
30
31 type entity = term E.entity (* attrs, uri, binder *)
32
33 type lenv = (int * id * bind) list (* location, name, binder *) 
34
35 type message = (lenv, term) Log.item list
36
37 (* helpers ******************************************************************)
38
39 let mk_uri si root s =
40    let kernel = if si then "bag-si" else "bag" in
41    String.concat "/" ["ld:"; kernel; root; s ^ ".ld"]
42
43 (* Currified constructors ***************************************************)
44
45 let abst w = Abst w
46
47 let abbr v = Abbr v
48
49 let lref i = LRef i
50
51 let cast u t = Cast (u, t)
52
53 let appl u t = Appl (u, t)
54
55 let bind l id b t = Bind (l, id, b, t)
56
57 let bind_abst l id u t = Bind (l, id, Abst u, t)
58
59 let bind_abbr l id v t = Bind (l, id, Abbr v, t)
60
61 (* location handling functions **********************************************)
62
63 let location = ref 0
64
65 let new_location () = let loc = !location in incr location; loc
66
67 let locations () = !location
68
69 (* local environment handling functions *************************************)
70
71 let empty_lenv = []
72
73 let push msg f es l id b =
74    let rec does_not_occur loc = function
75       | []                          -> true
76       | (l, _, _) :: _ when l = loc -> false
77       | _ :: es                     -> does_not_occur l es
78    in
79    if not (does_not_occur l es) then failwith msg else
80    let c = (l, id, b) :: es in f c
81
82 let append f es1 es2 = 
83    f (List.append es2 es1)
84
85 let map f map es =
86    Cps.list_map f map es
87
88 let contents f es = f es
89
90 let get f es i =
91    let rec aux = function
92       | []               -> f None
93       | (l, id, b) :: tl -> if l = i then f (Some (id, b)) else aux tl
94    in
95    aux es