]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/basic_ag/brg.ml
73da25b2db4628f6046df0f010a6e5008e06bcdd
[helm.git] / helm / software / lambda-delta / basic_ag / 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 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              (* reverse de Bruijn index *)
21          | GRef of uri              (* reference *)
22          | Cast of term * term      (* type, term *)
23          | Appl of term * term      (* argument, function *)
24          | Bind of id * bind * term (* 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
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 cast u t = Cast (u, t)
41
42 let appl u t = Appl (u, t)
43
44 let bind id b t = Bind (id, b, t)
45
46 let bind_abst id u t = Bind (id, Abst u, t)
47
48 let bind_abbr id v t = Bind (id, Abbr v, t)
49
50 (* context handling functions ***********************************************)
51
52 let empty_context = 0, []
53
54 let push f (l, es) id b =
55    let c = succ l, (id, b) :: es in 
56    f c
57
58 let append f (l1, es1) (l2, es2) =
59    f (l2 + l1, List.append es2 es1)
60
61 let map f map (l, es) =
62    let f es = f (l, es) in
63    Cps.list_map f map es
64
65 let contents f (l, es) = f l es
66
67 let get f (l, es) i =
68    if i < 0 || i >= l then f None else 
69    let result = List.nth es (l - succ i) in
70    f (Some result)
71