]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/basic_rg/brg.ml
we enabled the new style xml exportation, in particular for dual_rg
[helm.git] / helm / software / lambda-delta / basic_rg / brg.ml
index e42db3319b5739aea2bb9f00218b102f411adf35..baa83afed3741ca6f94637fec132262d7294a851 100644 (file)
 (* kernel version: basic, relative, global *)
 (* note          : ufficial basic lambda-delta *) 
 
-type uri = NUri.uri
-type id = Aut.id
+type uri = Entity.uri
+type id = Entity.id
+type attrs = Entity.attrs
 
-type bind = Void         (* exclusion *)
-          | Abst of term (* abstraction *)
-          | Abbr of term (* abbreviation *)
+type bind = Void of attrs        (* attrs       *)
+          | Abst of attrs * term (* attrs, type *)
+          | Abbr of attrs * term (* attrs, body *)
 
 and term = Sort of attrs * int         (* attrs, hierarchy index *)
          | LRef of attrs * int         (* attrs, position index *)
          | GRef of attrs * uri         (* attrs, reference *)
          | Cast of attrs * term * term (* attrs, type, term *)
          | Appl of attrs * term * term (* attrs, argument, function *)
-         | Bind of attrs * bind * term (* attrs, binder, scope *)
+         | Bind of bind * term         (* binder, scope *)
 
-and attr = Name of bool * id   (* real?, name *)
-         | Entry of int * bind (* age, binder *)
+type entity = term Entity.entity (* attrs, uri, binder *)
 
-and attrs = attr list
+type lenv = Null
+(* Cons: tail, relative local environment, binder *) 
+             | Cons of lenv * lenv option * bind 
 
-type obj = int * uri * bind (* age, uri, binder, contents *)
+(* helpers ******************************************************************)
 
-type item = obj option
-
-type context = (attrs * bind) list (* attrs, binder *) 
-
-type message = (context, term) Log.item list
+let mk_uri root s =
+   String.concat "/" ["ld:"; "brg"; root; s ^ ".ld"]
 
 (* Currified constructors ***************************************************)
 
-let abst w = Abst w
+let abst a w = Abst (a, w)
 
-let abbr v = Abbr v
+let abbr a v = Abbr (a, v)
 
 let lref a i = LRef (a, i)
 
@@ -51,38 +50,37 @@ let cast a u t = Cast (a, u, t)
 
 let appl a u t = Appl (a, u, t)
 
-let bind a b t = Bind (a, b, t)
-
-let bind_abst a u t = Bind (a, Abst u, t)
+let bind b t = Bind (b, t)
 
-let bind_abbr a v t = Bind (a, Abbr v, t)
+let bind_abst a u t = Bind (Abst (a, u), t)
 
-(* context handling functions ***********************************************)
+let bind_abbr a v t = Bind (Abbr (a, v), t)
 
-let empty_context = []
+(* local environment handling functions *************************************)
 
-let push f es a b =
-   let c = (a, b) :: es in f c
+let empty_lenv = Null
 
-let append f es1 es2 = 
-   f (List.append es2 es1)
+let push f es ?c b =
+   let es = Cons (es, c, b) in f es
 
-let map f map es =
-   Cps.list_map f map es
-
-let contents f es = f es
-
-let get f es i =
-   let rec aux e i = function
-      | []       -> f e None
-      | hd :: tl -> 
-         if i = 0 then f e (Some hd) else 
-        let e = match hd with _, Abst _ -> succ e | _ -> e in  
-        aux e (pred i) tl
+let get err f es i =
+   let rec aux j = function
+      | Null                            -> err ()
+      | Cons (tl, None, b)   when j = 0 -> f tl b
+      | Cons (_, Some c, b) when j = 0  -> f c b
+      | Cons (tl, _, _)                 -> aux (pred j) tl
    in
-   aux 0 i es
-
-let rec name f = function
-   | []               -> f None
-   | Name (r, n) :: _ -> f (Some (r, n))
-   | _ :: tl          -> name f tl
+   aux i es
+
+let rec rev_iter f map = function   
+   | Null                 -> f ()
+   | Cons (tl, None, b)   -> 
+      let f _ = map f tl b in rev_iter f map tl
+   | Cons (tl, Some c, b) -> 
+      let f _ = map f c b in rev_iter f map tl
+
+let rec fold_left f map x = function
+   | Null            -> f x
+   | Cons (tl, _, b) ->
+      let f x = fold_left f map x tl in
+      map f x b