]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/complete_rg/crg.ml
- dual_rg: renamed to complete_rg [as suggested in the ToCL documentation]
[helm.git] / helm / software / lambda-delta / complete_rg / crg.ml
diff --git a/helm/software/lambda-delta/complete_rg/crg.ml b/helm/software/lambda-delta/complete_rg/crg.ml
new file mode 100644 (file)
index 0000000..6db1b54
--- /dev/null
@@ -0,0 +1,78 @@
+(*
+    ||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_______________________________________________________________ *)
+
+(* kernel version: complete, relative, global *)
+(* note          : fragment of complete lambda-delta serving as abstract layer *) 
+
+type uri = Entity.uri
+type id = Entity.id
+type attrs = Entity.attrs
+
+type bind = Abst of term list (* domains *)
+          | Abbr of term list (* bodies  *)
+          | Void of int       (* number of exclusions *)
+
+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 = 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 s =
+   String.concat "/" ["ld:"; "crg"; root; s ^ ".ld"]
+
+let empty_lenv = ESort
+
+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
+     | ESort            -> err ()
+     | EBind (tl, a, _) ->
+        let err kk = aux f (succ i) (k + kk) tl in
+       let f j = f i j (k + j) 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 (tl, a, Abst [])     -> get_name err f i j tl
+   | EBind (tl, a, Abbr [])     -> get_name err f i j tl
+   | EBind (tl, a, Void 0)      -> get_name err f i j tl
+   | 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