X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fhelena%2Fsrc%2Fcomplete_rg%2Fcrg.ml;h=36a1c8d59bf83cf56932721080a99253ecfd9c38;hb=9a6cf8c3b53fe33515acd1aef8e7c7a10d71ae71;hp=a250d3edda087b68285d7bc1d7100b1a294b7d59;hpb=2cf2e883f91164ce614bdc86b5c5e2419b98f68d;p=helm.git diff --git a/helm/software/helena/src/complete_rg/crg.ml b/helm/software/helena/src/complete_rg/crg.ml index a250d3edd..36a1c8d59 100644 --- a/helm/software/helena/src/complete_rg/crg.ml +++ b/helm/software/helena/src/complete_rg/crg.ml @@ -18,24 +18,26 @@ module E = Entity type uri = E.uri type id = E.id -type attrs = E.node_attrs +type n_attrs = E.node_attrs +type b_attrs = E.bind_attrs -type bind = Abst of bool * N.layer * term (* x-reduced?, layer, type *) - | Abbr of term (* body *) - | Void (* *) -and term = TSort of attrs * int (* attrs, hierarchy index *) - | TLRef of attrs * int (* attrs, position indexe *) - | TGRef of attrs * uri (* attrs, reference *) - | TCast of attrs * term * term (* attrs, domain, element *) - | TAppl of attrs * bool * term * term (* attrs, extended?, argument, function *) - | TBind of attrs * bind * term (* attrs, binder, scope *) - | TProj of attrs * lenv * term (* attrs, closure, member *) +type bind = Abst of bool * N.layer * term (* x-reduced?, layer, type *) + | Abbr of term (* body *) + | Void (* *) -and lenv = ESort (* top *) - | EBind of lenv * attrs * bind (* environment, attrs, binder *) - | EAppl of lenv * attrs * bool * term (* environment, attrs, extended?, argument *) - | EProj of lenv * attrs * lenv (* environment, attrs, closure *) +and term = TSort of int (* hierarchy index *) + | TLRef of n_attrs * int (* attrs, position indexe *) + | TGRef of n_attrs * uri (* attrs, reference *) + | TCast of term * term (* domain, element *) + | TAppl of bool * term * term (* extended?, argument, function *) + | TBind of b_attrs * bind * term (* attrs, binder, scope *) + | TProj of lenv * term (* closure, member *) + +and lenv = ESort (* top *) + | EBind of lenv * n_attrs * b_attrs * bind (* environment, attrs, binder *) + | EAppl of lenv * bool * term (* environment, extended?, argument *) + | EProj of lenv * lenv (* environment, closure *) type entity = term E.entity @@ -43,100 +45,98 @@ type entity = term E.entity let empty_lenv = ESort -let push_bind f a b lenv = f (EBind (lenv, a, b)) +let push_bind f a y b lenv = f (EBind (lenv, a, y, b)) -let push_appl f a x t lenv = f (EAppl (lenv, a, x, t)) +let push_appl f x t lenv = f (EAppl (lenv, x, t)) -let push_proj f a e lenv = f (EProj (lenv, a, e)) +let push_proj f e lenv = f (EProj (lenv, e)) -let add_bind f a b t = f (TBind (a, b, t)) +let add_bind f y b t = f (TBind (y, b, t)) -let add_appl f a x v t = f (TAppl (a, x, v, t)) +let add_appl f x v t = f (TAppl (x, v, t)) -let add_proj f a e t = f (TProj (a, e, t)) +let add_proj f e t = f (TProj (e, t)) let rec shift f c t = match c with | ESort -> f t - | EBind (e, a, b) -> add_bind (shift f e) a b t - | EAppl (e, a, x, v) -> add_appl (shift f e) a x v t - | EProj (e, a, d) -> add_proj (shift f e) a d t + | EBind (e, _, y, b) -> add_bind (shift f e) y b t + | EAppl (e, x, v) -> add_appl (shift f e) x v t + | EProj (e, d) -> add_proj (shift f e) d t let rec append f c = function | ESort -> f c - | EBind (e, a, b) -> append (push_bind f a b) c e - | EAppl (e, a, x, t) -> append (push_appl f a x t) c e - | EProj (e, a, d) -> append (push_proj f a d) c e + | EBind (e, a, y, b) -> append (push_bind f a y b) c e + | EAppl (e, x, t) -> append (push_appl f x t) c e + | EProj (e, d) -> append (push_proj f d) c e let resolve_lref err f id lenv = let rec aux i = function | ESort -> err () - | EAppl (tl, _, _, _) -> aux i tl - | EBind (tl, a, _) -> - let f id0 _ = if id0 = id then f a i else aux (succ i) tl in + | EAppl (tl, _, _) -> aux i tl + | EBind (tl, a, y, _) -> + let f id0 _ = if id0 = id then f a y i else aux (succ i) tl in let err () = aux (succ i) tl in - E.name err f a - | EProj (tl, _, d) -> append (aux i) tl d + E.name err f y + | EProj (tl, d) -> append (aux i) tl d in aux 0 lenv let rec get_name err f i = function - | ESort -> err i - | EAppl (tl, _, _, _) -> get_name err f i tl - | EBind (_, a, _) when i = 0 -> + | ESort -> err i + | EAppl (tl, _, _) -> get_name err f i tl + | EBind (_, _, y, _) when i = 0 -> let err () = err i in - E.name err f a - | EBind (tl, _, _) -> get_name err f (pred i) tl - | EProj (tl, _, e) -> + E.name err f y + | EBind (tl, _, _, _) -> get_name err f (pred i) tl + | EProj (tl, e) -> let err i = get_name err f i tl in get_name err f i e let rec get e i = match e with - | ESort -> ESort, E.empty_node, Void - | EBind (e, a, b) when i = 0 -> e, a, b - | EBind (e, _, _) -> get e (pred i) - | EAppl (e, _, _, _) -> get e i - | EProj (e, _, d) -> get (append C.start e d) i + | ESort -> ESort, E.empty_node, E.empty_bind, Void + | EBind (e, a, y, b) when i = 0 -> e, a, y, b + | EBind (e, _, _, _) -> get e (pred i) + | EAppl (e, _, _) -> get e i + | EProj (e, d) -> get (append C.start e d) i let rec sub_list_strict f e l = match e, l with - | _, [] -> f e - | EBind (e, _, Abst _), _ :: tl -> sub_list_strict f e tl - | _ -> assert false + | _, [] -> f e + | EBind (e, _, _, Abst _), _ :: tl -> sub_list_strict f e tl + | _ -> assert false let rec fold_names f map x = function - | ESort -> f x - | EBind (e, {E.n_name = Some n}, Abst _) -> fold_names f map (map x n) e - | _ -> assert false + | ESort -> f x + | EBind (e, _, {E.b_name = Some n}, Abst _) -> fold_names f map (map x n) e + | _ -> assert false -let rec mem err f e b = match e with +let rec mem err f e y0 = match e with | ESort -> err () - | EBind (e, a, _) -> - if a.E.n_name = b.E.n_name then f () else mem err f e b - | EAppl (e, _, _, _) -> mem err f e b - | EProj (e, _, d) -> - let err () = mem err f e b in mem err f d b + | EBind (e, _, y, _) -> + if y.E.b_name = y0.E.b_name then f () else mem err f e y0 + | EAppl (e, _, _) -> mem err f e y0 + | EProj (e, d) -> + let err () = mem err f e y0 in mem err f d y0 let set_layer f n0 e = let rec aux f = function - | ESort -> f ESort - | EBind (e, a, Abst (r, n, w)) -> aux (push_bind f a (Abst (r, n0, w))) e - | EBind (e, a, b) -> aux (push_bind f a b) e - | EAppl (e, a, x, v) -> aux (push_appl f a x v) e - | EProj (e, a, d) -> let f d = aux (push_proj f a d) e in aux f d + | ESort -> f ESort + | EBind (e, a, y, Abst (r, n, w)) -> aux (push_bind f a y (Abst (r, n0, w))) e + | EBind (e, a, y, b) -> aux (push_bind f a y b) e + | EAppl (e, x, v) -> aux (push_appl f x v) e + | EProj (e, d) -> let f d = aux (push_proj f d) e in aux f d in aux f e -let set_attrs f a0 e = +let set_attrs f y0 e = let rec aux f = function | ESort -> f ESort - | EBind (e, a, b) -> - let a = E.compose a a0 in - aux (push_bind f a b) e - | EAppl (e, a, x, v) -> - let a = E.compose a a0 in - aux (push_appl f a x v) e - | EProj (e, a, d) -> - let a = E.compose a a0 in - let f d = aux (push_proj f a d) e in + | EBind (e, a, y, b) -> + let y = E.compose y y0 in + aux (push_bind f a y b) e + | EAppl (e, x, v) -> + aux (push_appl f x v) e + | EProj (e, d) -> + let f d = aux (push_proj f d) e in aux f d in aux f e