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