X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fdual_rg%2Fdrg.ml;h=ac4021c08db2a4a8e99b1bf6dcb288d6f932c98f;hb=f7bb626faf6b9d89c0ee5ac48b1d97c69d189f8a;hp=a300820465e7cc83de4d974009de453eca364135;hpb=cd798346d31b14b8947e5801b87dc4f363607862;p=helm.git diff --git a/helm/software/lambda-delta/dual_rg/drg.ml b/helm/software/lambda-delta/dual_rg/drg.ml index a30082046..ac4021c08 100644 --- a/helm/software/lambda-delta/dual_rg/drg.ml +++ b/helm/software/lambda-delta/dual_rg/drg.ml @@ -20,35 +20,56 @@ type bind = Abst of term list (* domains *) | Abbr of term list (* bodies *) | Void of int (* number of exclusions *) -and term = Sort of attrs * int (* attrs, hierarchy index *) - | LRef of attrs * int * int (* attrs, position indexes *) - | GRef of attrs * uri (* attrs, reference *) - | Cast of attrs * term * term (* attrs, domain, element *) - | Appl of attrs * term list * term (* attrs, arguments, function *) - | Proj of attrs * lenv * term (* attrs, closure, member *) - | Bind of attrs * bind * term (* attrs, binder, scope *) +and term = TSort of attrs * int (* attrs, hierarchy index *) + | TLRef of attrs * int * int (* attrs, position indexes *) + | TGRef of attrs * uri (* attrs, reference *) + | TCast of attrs * term * term (* attrs, domain, element *) + | TAppl of attrs * term list * term (* attrs, arguments, function *) + | TProj of attrs * lenv * term (* attrs, closure, member *) + | TBind of attrs * bind * term (* attrs, binder, scope *) -and lenv = Null - | Cons of lenv * attrs * bind (* closure, attrs, binder *) +and lenv = ESort (* top *) + | EProj of lenv * attrs * lenv (* environment, attrs, closure *) + | EBind of lenv * attrs * bind (* environment, attrs, binder *) type entity = term Entity.entity (* helpers ******************************************************************) -let mk_uri root f s = - let str = String.concat "/" ["ld:"; "drg"; root; s ^ ".ld"] in - f str +let mk_uri root s = + String.concat "/" ["ld:"; "drg"; root; s ^ ".ld"] -let empty_lenv = Null +let empty_lenv = ESort -let push f lenv a b = f (Cons (lenv, a, b)) +let push_bind f lenv a b = f (EBind (lenv, a, b)) +let push_proj f lenv a e = f (EProj (lenv, a, e)) + +let push2 err f lenv attr ?t = match lenv, t with + | EBind (e, a, Abst ws), Some t -> f (EBind (e, (attr :: a), Abst (t :: ws))) + | EBind (e, a, Abbr vs), Some t -> f (EBind (e, (attr :: a), Abbr (t :: vs))) + | EBind (e, a, Void n), None -> f (EBind (e, (attr :: a), Void (succ n))) + | _ -> err () + +(* this id not tail recursive *) let resolve_lref err f id lenv = let rec aux f i k = function - | Null -> err () - | Cons (tl, a, _) -> + | ESort -> err () + | EBind (tl, a, _) -> let err kk = aux f (succ i) (k + kk) tl in let f j = f i j k in Entity.resolve err f id a + | EProj _ -> assert false (* TODO *) in aux f 0 0 lenv + +let rec get_name err f i j = function + | ESort -> err i + | EBind (_, a, _) when i = 0 -> + let err () = err i in + Entity.get_name err f j a + | EBind (tl, _, _) -> + get_name err f (pred i) j tl + | EProj (tl, _, e) -> + let err i = get_name err f i j tl in + get_name err f i j e