X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fbasic_rg%2Fbrg.ml;h=baa83afed3741ca6f94637fec132262d7294a851;hb=f00757144b2cd7e6457fed55dbc1309d11a542dc;hp=a3a32f8d0fd6855a3b0d21295488e9847364d4c9;hpb=b0f7c07bc4115c795f17ac319ee795a6d8118b22;p=helm.git diff --git a/helm/software/lambda-delta/basic_rg/brg.ml b/helm/software/lambda-delta/basic_rg/brg.ml index a3a32f8d0..baa83afed 100644 --- a/helm/software/lambda-delta/basic_rg/brg.ml +++ b/helm/software/lambda-delta/basic_rg/brg.ml @@ -1,15 +1,86 @@ -module U = NUri -module A = Aut +(* + ||M|| This file is part of HELM, an Hypertextual, Electronic + ||A|| Library of Mathematics, developed at the Computer Science + ||T|| Department, University of Bologna, Italy. + ||I|| + ||T|| HELM is free software; you can redistribute it and/or + ||A|| modify it under the terms of the GNU General Public License + \ / version 2 or (at your option) any later version. + \ / This software is distributed as is, NO WARRANTY. + V_______________________________________________________________ *) -type uri = U.uri -type id = A.id +(* kernel version: basic, relative, global *) +(* note : ufficial basic lambda-delta *) -type binder = Abst | Abbr +type uri = Entity.uri +type id = Entity.id +type attrs = Entity.attrs -type term = Sort of int - | LRef of int - | GRef of uri - | Cast of term * term - | Appl of term * term - | Bind of id * binder * term * term - +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 bind * term (* binder, scope *) + +type entity = term Entity.entity (* attrs, uri, binder *) + +type lenv = Null +(* Cons: tail, relative local environment, binder *) + | Cons of lenv * lenv option * bind + +(* helpers ******************************************************************) + +let mk_uri root s = + String.concat "/" ["ld:"; "brg"; root; s ^ ".ld"] + +(* Currified constructors ***************************************************) + +let abst a w = Abst (a, w) + +let abbr a v = Abbr (a, 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 b t = Bind (b, t) + +let bind_abst a u t = Bind (Abst (a, u), t) + +let bind_abbr a v t = Bind (Abbr (a, v), t) + +(* local environment handling functions *************************************) + +let empty_lenv = 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