]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/basic_rg/brg.ml
brg: change in the representation of binders
[helm.git] / helm / software / lambda-delta / basic_rg / brg.ml
index 6a9f9fd2088b4c260e75d9ffaca19f567748d0a4..fd93f397af56bf450ce8ef1452697f004ce7b3e5 100644 (file)
 (* kernel version: basic, relative, global *)
 (* note          : ufficial basic lambda-delta *) 
 
-type uri = Item.uri
-type id = Item.id
+type uri = Entity.uri
+type id = Entity.id
+type attrs = Entity.attrs
 
-type attr = Name of bool * id  (* real?, name *)
-          | Apix of int        (* additional position index *)
-
-type attrs = attr list
-
-type bind = Void of attrs        (* attrs       *)
-          | Abst of attrs * term (* attrs, type *)
-          | Abbr of attrs * term (* attrs, body *)
+type bind = Void         (*      *)
+          | Abst of term (* type *)
+          | Abbr of term (* 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 bind * term         (* binder, scope *)
+         | Bind of attrs * bind * term (* attrs, binder, scope *)
+
+type entity = term Entity.entity (* attrs, uri, binder *)
 
-type obj = bind Item.obj (* age, uri, binder *)
+type lenv = Null
+(* Cons: tail, relative local environment, attrs, binder *) 
+          | Cons of lenv * lenv * attrs * bind 
 
-type item = bind Item.item
+(* helpers ******************************************************************)
 
-type context = Null
-(* Cons: tail, relative context, binder *) 
-             | Cons of context * context option * bind 
+let mk_uri root s =
+   String.concat "/" ["ld:"; "brg"; root; s ^ ".ld"]
 
 (* Currified constructors ***************************************************)
 
-let abst a w = Abst (a, w)
+let abst w = Abst w
 
-let abbr a v = Abbr (a, v)
+let abbr v = Abbr v
 
 let lref a i = LRef (a, i)
 
@@ -51,47 +50,33 @@ let cast a u t = Cast (a, u, t)
 
 let appl a u t = Appl (a, u, t)
 
-let bind b t = Bind (b, t)
+let bind a b t = Bind (a, b, t)
 
-let bind_abst a u t = Bind (Abst (a, u), t)
+let bind_abst a u t = Bind (a, Abst u, t)
 
-let bind_abbr a v t = Bind (Abbr (a, v), t)
+let bind_abbr a v t = Bind (a, Abbr v, t)
 
-(* context handling functions ***********************************************)
+let bind_void a t = Bind (a, Void, t)
 
-let empty_context = Null
+(* local environment handling functions *************************************)
 
-let push f es ?c b =
-   let es = Cons (es, c, b) in f es
+let empty = Null
 
-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 i es
+let push e c a b = Cons (e, c, a, b)
 
-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 get i = function
+   | Null                         -> Null, Null, [], Void
+   | Cons (e, c, a, b) when i = 0 -> e, c, a, b
+   | Cons (e, _, _, _)            -> get (pred i) e
 
-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
+let get e i = get i e
 
-let rec name err f = function
-   | []               -> err ()
-   | Name (r, n) :: _ -> f n r
-   | _ :: tl          -> name err f tl
+(* used in BrgOutput.pp_lenv *)
+let rec fold_right f map e x = match e with   
+   | Null              -> f x
+   | Cons (e, c, a, b) -> fold_right (map f e c a b) map e x
 
-let rec apix err f = function
-   | []          -> err ()
-   | Apix i :: _ -> f i
-   | _ :: tl     -> apix err f tl
+(* used in MetaBrg.unwind_to_xlate_term *)
+let rec fold_left map x = function
+   | Null              -> x
+   | Cons (e, _, a, b) -> fold_left map (map x a b) e