]> matita.cs.unibo.it Git - helm.git/blobdiff - components/acic_procedural/proceduralConversion.ml
Procedural: some improvements
[helm.git] / components / acic_procedural / proceduralConversion.ml
index b3ce560707348f38f7bd9de27306bd0cc3dc6bdc..77b5a181783ae597c3e0a785c9c105918a20f07b 100644 (file)
@@ -32,6 +32,7 @@ module UM   = UriManager
 
 module T    = ProceduralTypes
 module Cl   = ProceduralClassify
+module M    = ProceduralMode
 
 (* helpers ******************************************************************)
 
@@ -174,3 +175,48 @@ try
    let args = eliminator :: lps @ predicate :: lifted_cases @ rps @ [arg] in
    Some (C.AAppl (id, args))
 with Invalid_argument _ -> failwith "PCn.mk_ind"
+
+let apply_substs substs =
+   let length = List.length substs in
+   let rec apply_xns k (uri, t) = uri, apply_term k t
+   and apply_ms k = function
+      | None   -> None
+      | Some t -> Some (apply_term k t)
+   and apply_fix len k (id, name, i, ty, bo) =
+      id, name, i, apply_term k ty, apply_term (k + len) bo
+   and apply_cofix len k (id, name, ty, bo) =
+      id, name, apply_term k ty, apply_term (k + len) bo
+   and apply_term k = function
+      | C.ASort _ as t -> t
+      | C.AImplicit _ as t -> t
+      | C.ARel (id, rid, m, b) as t -> 
+         if m < k || m >= length + k then t 
+        else lift 1 k (List.nth substs (m - k))
+      | C.AConst (id, uri, xnss) -> C.AConst (id, uri, List.map (apply_xns k) xnss)
+      | C.AVar (id, uri, xnss) -> C.AVar (id, uri, List.map (apply_xns k) xnss)
+      | C.AMutInd (id, uri, tyno, xnss) -> C.AMutInd (id, uri, tyno, List.map (apply_xns k) xnss)
+      | C.AMutConstruct (id, uri, tyno, consno, xnss) -> C.AMutConstruct (id, uri,tyno,consno, List.map (apply_xns k) xnss)
+      | C.AMeta (id, i, mss) -> C.AMeta(id, i, List.map (apply_ms k) mss)
+      | C.AAppl (id, ts) -> C.AAppl (id, List.map (apply_term k) ts)
+      | C.ACast (id, te, ty) -> C.ACast (id, apply_term k te, apply_term k ty)
+      | C.AMutCase (id, sp, i, outty, t, pl) -> C.AMutCase (id, sp, i, apply_term k outty, apply_term k t, List.map (apply_term k) pl)
+      | C.AProd (id, n, s, t) -> C.AProd (id, n, apply_term k s, apply_term (succ k) t)
+      | C.ALambda (id, n, s, t) -> C.ALambda (id, n, apply_term k s, apply_term (succ k) t)
+      | C.ALetIn (id, n, s, t) -> C.ALetIn (id, n, apply_term k s, apply_term (succ k) t)
+      | C.AFix (id, i, fl) -> C.AFix (id, i, List.map (apply_fix (List.length fl) k) fl)
+      | C.ACoFix (id, i, fl) -> C.ACoFix (id, i, List.map (apply_cofix (List.length fl) k) fl)
+   in
+   apply_term 1
+
+let hole = C.AImplicit ("", Some `Hole)
+
+let mk_pattern rps predicate = hole
+(*   let rec clear_absts n = function
+      | C.ALambda (_, _, _, t) when n > 0 -> clear_absts (pred n) t
+(*      | t                      when n > 0 -> assert false *)
+      | t                                 -> t
+   in
+   let substs = hole :: List.rev rps in
+   let body = clear_absts (succ (List.length rps)) predicate in
+   if M.is_appl true (cic body) then apply_substs substs body else hole
+*)