X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Fsoftware%2Flambda-delta%2Fbasic_rg%2Fbrg.ml;h=6a9f9fd2088b4c260e75d9ffaca19f567748d0a4;hb=0dc347a7742e40a828fa98acba70078dd2d7cbd5;hp=4778e5c3e9ef8716a46ccff050ecb211eef90eda;hpb=75620ca64e3038fcbebb51559fdc31b2e8a00f93;p=helm.git diff --git a/helm/software/lambda-delta/basic_rg/brg.ml b/helm/software/lambda-delta/basic_rg/brg.ml index 4778e5c3e..6a9f9fd20 100644 --- a/helm/software/lambda-delta/basic_rg/brg.ml +++ b/helm/software/lambda-delta/basic_rg/brg.ml @@ -9,59 +9,89 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -type uri = NUri.uri -type id = Aut.id +(* kernel version: basic, relative, global *) +(* note : ufficial basic lambda-delta *) -type bind = Void (* exclusion *) - | Abst of term (* abstraction *) - | Abbr of term (* abbreviation *) +type uri = Item.uri +type id = Item.id -and term = Sort of int (* hierarchy index *) - | LRef of int (* reverse de Bruijn index *) - | GRef of uri (* reference *) - | Cast of term * term (* type, term *) - | Appl of term * term (* argument, function *) - | Bind of id * bind * term (* name, binder, scope *) +type attr = Name of bool * id (* real?, name *) + | Apix of int (* additional position index *) -type obj = int * uri * bind (* age, uri, binder, contents *) +type attrs = attr list -type item = obj option +type bind = Void of attrs (* attrs *) + | Abst of attrs * term (* attrs, type *) + | Abbr of attrs * term (* attrs, body *) -type context = int * (id * bind) list +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 *) -type message = (context, term) Log.item list +type obj = bind Item.obj (* age, uri, binder *) -(* Currified constructors ***************************************************) +type item = bind Item.item -let abst w = Abst w +type context = Null +(* Cons: tail, relative context, binder *) + | Cons of context * context option * bind -let abbr v = Abbr v +(* Currified constructors ***************************************************) -let cast u t = Cast (u, t) +let abst a w = Abst (a, w) -let appl u t = Appl (u, t) +let abbr a v = Abbr (a, v) -let bind id b t = Bind (id, b, t) +let lref a i = LRef (a, i) -(* context handling functions ***********************************************) +let cast a u t = Cast (a, u, t) -let empty_context = 0, [] +let appl a u t = Appl (a, u, t) -let push f (l, es) id b = - let c = succ l, (id, b) :: es in - f c +let bind b t = Bind (b, t) -let append f (l1, es1) (l2, es2) = - f (l2 + l1, List.append es2 es1) +let bind_abst a u t = Bind (Abst (a, u), t) -let map f map (l, es) = - let f es = f (l, es) in - Cps.list_map f map es +let bind_abbr a v t = Bind (Abbr (a, v), t) -let contents f (l, es) = f l es - -let get f (l, es) i = - if i < 0 || i >= l then f None else - let result = List.nth es (l - succ i) in - f (Some result) +(* context handling functions ***********************************************) +let empty_context = Null + +let push f es ?c b = + let es = Cons (es, c, b) in f es + +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 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