]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/src/basic_ag/bag.ml
Matitaweb: layout change in the matitaweb inteface, in order to allow better
[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 attrs = E.attrs
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 attrs * int * bind * term (* name, location, binder, scope *)
30
31 type entity = term E.entity (* attrs, uri, binder *)
32
33 type lenv = (attrs * int * bind) list (* location, name, binder *) 
34
35 type message = (lenv, term) Log.item list
36
37 (* Currified constructors ***************************************************)
38
39 let abst w = Abst w
40
41 let abbr v = Abbr v
42
43 let lref i = LRef i
44
45 let cast u t = Cast (u, t)
46
47 let appl u t = Appl (u, t)
48
49 let bind a l b t = Bind (a, l, b, t)
50
51 let bind_abst a l u t = Bind (a, l, Abst u, t)
52
53 let bind_abbr a l v t = Bind (a, l, Abbr v, t)
54
55 (* local environment handling functions *************************************)
56
57 let empty_lenv = []
58
59 let push msg f es a l b =
60    let rec does_not_occur loc = function
61       | []                          -> true
62       | (_, l, _) :: _ when l = loc -> false
63       | _ :: es                     -> does_not_occur l es
64    in
65    if not (does_not_occur l es) then failwith msg else
66    let c = (a, l, b) :: es in f c
67
68 let append f es1 es2 = 
69    f (List.append es2 es1)
70
71 let map f map es =
72    Cps.list_map f map es
73
74 let contents f es = f es
75
76 let get err f es i =
77    let rec aux = function
78       | []              -> err ()
79       | (a, l, b) :: tl -> if l = i then f a b else aux tl
80    in
81    aux es
82
83 let nth err f loc e =
84    let rec aux n = function
85       | []                          -> err loc
86       | (_, l, _) :: _ when l = loc -> f n
87       | _ :: e                      -> aux (succ n) e
88    in
89    aux 0 e