X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fbasic_rg%2Fbrg.ml;h=d0a442807a39015da92630c6f03f1b2aac3f2827;hb=a82bb964ad0bf0969dae008a4de854532846e455;hp=d62a130a4c526c06e6e9f38fa2b864f11a6c686e;hpb=c8011c7ad75be5d03c4d4bb2e6900af32ad65c07;p=helm.git diff --git a/helm/software/lambda-delta/basic_rg/brg.ml b/helm/software/lambda-delta/basic_rg/brg.ml index d62a130a4..d0a442807 100644 --- a/helm/software/lambda-delta/basic_rg/brg.ml +++ b/helm/software/lambda-delta/basic_rg/brg.ml @@ -12,38 +12,38 @@ (* kernel version: basic, relative, global *) (* note : ufficial basic lambda-delta *) -type uri = Item.uri -type id = Item.id +type uri = Unit.uri +type id = Unit.id -type bind = Void (* exclusion *) - | Abst of term (* abstraction *) - | Abbr of term (* abbreviation *) +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 *) 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 *) - -and attr = Name of bool * id (* real?, name *) - | Entry of int * bind (* age, binder *) - -and attrs = attr list - -type obj = bind Item.obj (* age, uri, binder *) + | Bind of bind * term (* binder, scope *) -type item = bind Item.item +type entry = bind Unit.entry (* age, uri, binder *) -type context = (attrs * bind) list (* attrs, binder *) +type unit = bind Unit.unit -type message = (context, term) Log.item list +type lenv = Null +(* Cons: tail, relative local environment, binder *) + | Cons of lenv * lenv option * bind (* 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 +51,47 @@ 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 b t = Bind (b, t) -let bind_abst a u t = Bind (a, Abst u, t) +let bind_abst a u t = Bind (Abst (a, u), t) -let bind_abbr a v t = Bind (a, Abbr v, t) +let bind_abbr a v t = Bind (Abbr (a, v), t) -(* context handling functions ***********************************************) +(* local environment handling functions *************************************) -let empty_context = [] +let empty_lenv = Null -let push f es a b = - let c = (a, b) :: es in f c +let push f es ?c b = + let es = Cons (es, c, b) in f es -let append f es1 es2 = - f (List.append es2 es1) - -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 + +let rec name err f = function + | [] -> err () + | Name (r, n) :: _ -> f n r + | _ :: tl -> name err f tl + +let rec apix err f = function + | [] -> err () + | Apix i :: _ -> f i + | _ :: tl -> apix err f tl