]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_refiner/nCicMetaSubst.ml
Let's use already existent functions.
[helm.git] / helm / software / components / ng_refiner / nCicMetaSubst.ml
index bdd0adfe014f3acba18eab6a1270c55527d012d5..6deaaf572b7914f9ad3edba29b1a937b4bc1a711 100644 (file)
@@ -207,11 +207,18 @@ and restrict metasenv subst i restrictions =
 ;;
 
 let rec flexible_arg context subst = function 
-  | NCic.Meta (i,_) | NCic.Appl (NCic.Meta (i,_) :: _)-> 
+  | NCic.Meta (i,_) ->
       (try 
         let _,_,t,_ = List.assoc i subst in
         flexible_arg context subst t
       with Not_found -> true)
+  | NCic.Appl (NCic.Meta (i,_) :: args)-> 
+      (try 
+        let _,_,t,_ = List.assoc i subst in
+        flexible_arg context subst 
+          (NCicReduction.head_beta_reduce ~delta:max_int 
+            (NCic.Appl (t :: args)))
+      with Not_found -> true)
    (* this is a cheap whd, it only performs zeta-reduction.
     * 
     * it works when the **omissis** disambiguation algorithm
@@ -454,26 +461,31 @@ let delift ~unify metasenv subst context n l t =
         raise (MetaSubstFailure msg)
 ;;
 
-let mk_meta ?(attrs=[]) metasenv context ty = 
-  let tyof = List.map (function `Name s -> `Name ("typeof_"^s) | x -> x) in
-  let rec mk_meta attrs n metasenv context = function
-  | `WithType ty ->
-    let len = List.length context in
-    let menv_entry = (n, (attrs, context, ty)) in
-    menv_entry :: metasenv, n, NCic.Meta (n, (0,NCic.Irl len)), ty
-  | `Sort ->
-    let ty = NCic.Implicit (`Typeof n) in
-    mk_meta (tyof attrs) n metasenv [] (`WithType ty)
-  | `Type ->
-    let metasenv, _, ty, _ = 
-      mk_meta (tyof attrs) (newmeta ()) metasenv context `Sort in
-    mk_meta attrs n metasenv context (`WithType ty)
-  | `Term ->
-    let metasenv, _, ty, _ = 
-      mk_meta (tyof attrs) (newmeta ()) metasenv context `Type in
-    mk_meta attrs n metasenv context (`WithType ty)
-  in
-    mk_meta attrs (newmeta ()) metasenv context ty
+let mk_meta ?(attrs=[]) metasenv context ?with_type kind = 
+  assert(kind <> `IsSort || context = []);
+  let n = newmeta () in
+  let ty= match with_type with None-> NCic.Implicit (`Typeof n)| Some x ->x in
+  let len = List.length context in
+  let attrs = NCicUntrusted.set_kind kind attrs in
+  let menv_entry = (n, (attrs, context, ty)) in
+  menv_entry :: metasenv, n, NCic.Meta (n, (0,NCic.Irl len)), ty
+;;
+
+let extend_meta metasenv n =
+ try
+  let attrs,cc,ty = NCicUtils.lookup_meta n metasenv in 
+  (match ty with 
+  | NCic.Implicit (`Typeof _) -> 
+      let mk_meta context kind =
+        let metasenv, _, ty, _ = mk_meta metasenv context kind in
+        (n, (attrs, cc, ty)) :: List.filter (fun x,_ -> x <> n) metasenv, ty
+      in
+      (match NCicUntrusted.kind_of_meta attrs with
+       | `IsSort 
+       | `IsType -> mk_meta [] `IsSort
+       | `IsTerm -> mk_meta cc `IsType)
+  | ty -> metasenv, ty)
+ with NCicUtils.Meta_not_found _ -> assert false
 ;;
 
 let saturate ?(delta=0) metasenv subst context ty goal_arity =
@@ -481,7 +493,7 @@ let saturate ?(delta=0) metasenv subst context ty goal_arity =
   let rec aux metasenv = function
    | NCic.Prod (name,s,t) as ty ->
        let metasenv1, _, arg,_ = 
-          mk_meta ~attrs:[`Name name] metasenv context (`WithType s) in
+          mk_meta ~attrs:[`Name name] metasenv context ~with_type:s `IsTerm in
        let t, metasenv1, args, pno = 
            aux metasenv1 (NCicSubstitution.subst arg t) 
        in