X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fbasic_rg%2Fbrg.ml;h=5ad05a72f7da075221bedd10490b63900ddcf438;hb=bc9fca01f135aecc2940e7318f77fea34fd6ef30;hp=eaaeb6e6054c8c3fc426b74cd776f0256e89985d;hpb=c45c77de154323feaf5bf6aee98c86b95361b9ae;p=helm.git diff --git a/helm/software/lambda-delta/basic_rg/brg.ml b/helm/software/lambda-delta/basic_rg/brg.ml index eaaeb6e60..5ad05a72f 100644 --- a/helm/software/lambda-delta/basic_rg/brg.ml +++ b/helm/software/lambda-delta/basic_rg/brg.ml @@ -9,18 +9,91 @@ \ / 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 = Abst | Abbr (* abstraction, abbreviation *) +type uri = Item.uri +type id = Item.id -type 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 * term (* name, binder, content, scope *) +type attr = Name of bool * id (* real?, name *) + | Apix of int (* additional position index *) -type obj = bind * term (* binder, contents *) +type attrs = attr list -type item = (obj * uri) option (* uri, object *) +type bind = Void (* exclusion *) + | Abst of term (* abstraction *) + | Abbr of term (* abbreviation *) + +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 *) + +type obj = bind Item.obj (* age, uri, binder *) + +type item = bind Item.item + +type context = Null +(* Cons: tail, relative context, attrs, binder *) + | Cons of context * context option * attrs * bind + +type message = (context, term) Log.item list + +(* Currified constructors ***************************************************) + +let abst w = Abst w + +let abbr v = Abbr v + +let lref a i = LRef (a, i) + +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_abbr a v t = Bind (a, Abbr v, t) + +(* context handling functions ***********************************************) + +let empty_context = Null + +let push f es ?c a b = + let es = Cons (es, c, a, b) in f es + +let get err f es i = + let rec aux j = function + | Null -> err i + | Cons (tl, None, a, b) when j = 0 -> f tl a b + | Cons (_, Some c, a, b) when j = 0 -> f c a b + | Cons (tl, _, _, _) -> aux (pred j) tl + in + aux i es + +let rec rev_iter f map = function + | Null -> f () + | Cons (tl, None, a, b) -> + let f () = map f tl a b in rev_iter f map tl + | Cons (tl, Some c, a, b) -> + let f () = map f c a b in rev_iter f map tl + +let rec fold_left f map x = function + | Null -> f x + | Cons (tl, _, a, b) -> + let f x = fold_left f map x tl in + map f x a 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