]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/tactics/primitiveTactics.ml
CSC: hack to make applications of constants that have a Type sort which
[helm.git] / helm / ocaml / tactics / primitiveTactics.ml
index 518c6f86acc5daaa36c3724c2b404276972020dd..1631e767fb7a5f59f7482a598081195267969f5b 100644 (file)
@@ -37,13 +37,13 @@ exception WrongUriToVariable of string
 (* and [bo] = Lambda/LetIn [context].(Meta [newmeta])       *)
 (* So, lambda_abstract is the core of the implementation of *)
 (* the Intros tactic.                                       *)
-let lambda_abstract context newmeta ty mk_fresh_name =
+let lambda_abstract metasenv context newmeta ty mk_fresh_name =
  let module C = Cic in
   let rec collect_context context =
    function
       C.Cast (te,_)   -> collect_context context te
     | C.Prod (n,s,t)  ->
-       let n' = mk_fresh_name context n ~typ:s in
+       let n' = mk_fresh_name metasenv context n ~typ:s in
         let (context',ty,bo) =
          collect_context ((Some (n',(C.Decl s)))::context) t
         in
@@ -74,7 +74,7 @@ let eta_expand metasenv context t arg =
         C.Var (uri,exp_named_subst')
     | C.Meta _
     | C.Sort _
-    | C.Implicit as t -> t
+    | C.Implicit as t -> t
     | C.Cast (te,ty) -> C.Cast (aux n te, aux n ty)
     | C.Prod (nn,s,t) -> C.Prod (nn, aux n s, aux (n+1) t)
     | C.Lambda (nn,s,t) -> C.Lambda (nn, aux n s, aux (n+1) t)
@@ -115,7 +115,8 @@ let eta_expand metasenv context t arg =
     T.type_of_aux' metasenv context arg
    in
     let fresh_name =
-     ProofEngineHelpers.mk_fresh_name context (Cic.Name "Heta") ~typ:argty
+     FreshNamesGenerator.mk_fresh_name
+      metasenv context (Cic.Name "Heta") ~typ:argty
     in
      (C.Appl [C.Lambda (fresh_name,argty,aux 0 t) ; arg])
 
@@ -159,6 +160,21 @@ let new_metasenv_for_apply newmeta proof context ty =
   let rec aux newmeta =
    function
       C.Cast (he,_) -> aux newmeta he
+      (* If the expected type is a Type, then also Set is OK ==>
+      *  we accept any term of type Type *)
+      (*CSC: BUG HERE: in this way it is possible for the term of
+      * type Type to be different from a Sort!!! *)
+    | C.Prod (name,(C.Sort C.Type as s),t) ->
+       let irl =
+         CicMkImplicit.identity_relocation_list_for_metavariable context
+       in
+        let newargument = C.Meta (newmeta+1,irl) in
+         let (res,newmetasenv,arguments,lastmeta) =
+          aux (newmeta + 2) (S.subst newargument t)
+         in
+          res,
+           (newmeta,[],s)::(newmeta+1,context,C.Meta (newmeta,[]))::newmetasenv,
+           newargument::arguments,lastmeta
     | C.Prod (name,s,t) ->
        let irl =
          CicMkImplicit.identity_relocation_list_for_metavariable context
@@ -264,19 +280,17 @@ let apply_tac ~term ~status:(proof, goal) =
      | _ -> [],newmeta,[],term
    in
    let metasenv' = metasenv@newmetasenvfragment in
-prerr_endline ("^^^^^TERM': " ^ CicPp.ppterm term') ; 
    let termty =
     CicSubstitution.subst_vars exp_named_subst_diff
      (CicTypeChecker.type_of_aux' metasenv' context term)
    in
-prerr_endline ("^^^^^TERMTY: " ^ CicPp.ppterm termty) ; 
     (* newmeta is the lowest index of the new metas introduced *)
     let (consthead,newmetas,arguments,_) =
      new_metasenv_for_apply newmeta' proof context termty
     in
      let newmetasenv = metasenv'@newmetas in
       let subst,newmetasenv' =
-       CicUnification.fo_unif newmetasenv context consthead ty
+        CicUnification.fo_unif newmetasenv context consthead ty
       in
        let in_subst_domain i = List.exists (function (j,_) -> i=j) subst in
        let apply_subst = CicMetaSubst.apply_subst subst in
@@ -312,7 +326,7 @@ let apply_tac ~term ~status =
     raise (Fail (Printexc.to_string e))
 
 let intros_tac
- ?(mk_fresh_name_callback = ProofEngineHelpers.mk_fresh_name) ()
+ ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name) ()
  ~status:(proof, goal)
 =
  let module C = Cic in
@@ -321,7 +335,7 @@ let intros_tac
   let metano,context,ty = CicUtil.lookup_meta goal metasenv in
    let newmeta = new_meta_of_proof ~proof in
     let (context',ty',bo') =
-     lambda_abstract context newmeta ty mk_fresh_name_callback
+     lambda_abstract metasenv context newmeta ty mk_fresh_name_callback
     in
      let (newproof, _) =
        subst_meta_in_proof proof metano bo' [newmeta,context',ty']
@@ -329,7 +343,7 @@ let intros_tac
       (newproof, [newmeta])
 
 let cut_tac
- ?(mk_fresh_name_callback = ProofEngineHelpers.mk_fresh_name)
+ ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name)
  term ~status:(proof, goal)
 =
  let module C = Cic in
@@ -338,7 +352,7 @@ let cut_tac
    let newmeta1 = new_meta_of_proof ~proof in
    let newmeta2 = newmeta1 + 1 in
    let fresh_name =
-    mk_fresh_name_callback context (Cic.Name "Hcut") ~typ:term in
+    mk_fresh_name_callback metasenv context (Cic.Name "Hcut") ~typ:term in
    let context_for_newmeta1 =
     (Some (fresh_name,C.Decl term))::context in
    let irl1 =
@@ -361,7 +375,7 @@ let cut_tac
       (newproof, [newmeta1 ; newmeta2])
 
 let letin_tac
- ?(mk_fresh_name_callback = ProofEngineHelpers.mk_fresh_name)
+ ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name)
  term ~status:(proof, goal)
 =
  let module C = Cic in
@@ -370,7 +384,7 @@ let letin_tac
    let _ = CicTypeChecker.type_of_aux' metasenv context term in
     let newmeta = new_meta_of_proof ~proof in
     let fresh_name =
-     mk_fresh_name_callback context (Cic.Name "Hletin") ~typ:term in
+     mk_fresh_name_callback metasenv context (Cic.Name "Hletin") ~typ:term in
     let context_for_newmeta =
      (Some (fresh_name,C.Def (term,None)))::context in
     let irl =
@@ -499,7 +513,7 @@ da subst1!!!! Dovrei rimuoverle o sono innocue?*)
               let apply_subst _ t =
                let t' = CicMetaSubst.apply_subst subst1 t in
                 CicMetaSubst.apply_subst_reducing
-                 subst2 (Some (emeta,List.length fargs)) t'
+                 (Some (emeta,List.length fargs)) subst2 t'
               in
                 let old_uninstantiatedmetas,new_uninstantiatedmetas =
                  classify_metas newmeta in_subst_domain apply_subst
@@ -521,8 +535,8 @@ da subst1!!!! Dovrei rimuoverle o sono innocue?*)
                      let apply_subst' t =
                       let t' = CicMetaSubst.apply_subst subst1 t in
                        CicMetaSubst.apply_subst_reducing
-                        ((metano,bo')::subst2)
-                        (Some (emeta,List.length fargs)) t'
+                        (Some (emeta,List.length fargs))
+                        ((metano,bo')::subst2) t'
                      in
                       subst_meta_and_metasenv_in_proof
                         proof metano apply_subst' newmetasenv'''