Coq 在战术/战术符号内匹配上下文模式

Coq 在战术/战术符号内匹配上下文模式,coq,coq-tactic,Coq,Coq Tactic,我通过战术在我的球门内找到了一个模式 为什么会失败: Tactic Notation "my_context_match" uconstr(g) := match goal with | |- context[g] => idtac end. my_context_match _. 当这成功的时候 match goal with | |- context[

我通过战术在我的球门内找到了一个模式

为什么会失败:

        Tactic Notation "my_context_match" uconstr(g) :=
          match goal with
          | |- context[g] => idtac
          end.

          my_context_match _.
当这成功的时候

        match goal with
          | |- context[_] => idtac
        end.


有没有办法写一个
mycontext\u match
,这样我就可以传递不完整的模式(上面有
),看看我的目标中是否有匹配的模式?

uconstr
的支持非常零碎。我刚刚报告。请注意,即使这样也会失败:

Goal True.
  let v := uconstr:(True) in
  lazymatch constr:(v) with
  | v => idtac
  end. (* Error: No matching clauses for match. *)

正如@eponier在评论中所建议的,您可以使用
open\u constr
而不是
uconstr
。然而,这将留下未解决的EVAR。这是一个有效的策略,不会留下未解决的评估:

Tactic Notation "my_context_match" uconstr(g) :=
  (* [match] does not support [uconstr], cf COQBUG(https://github.com/coq/coq/issues/9321),
     so we use [open_constr] *)
  let g := open_constr:(g) in
  (* turning [g] into an [open_constr] creates new evars, so we must
     eventually unify them with the goal *)
  let G := match goal with |- ?G => G end in
  (* We now search for [g] in the goal, and then replace the matching
     subterm with the [open_constr] [g], so that we can unify the
     result with the goal [G] to resolve the new evars we created *)
  match G with
  | context cG[g]
    => let G' := context cG[g] in
       unify G G'
  end.

Goal True /\ True.
  my_context_match _.
  my_context_match (_ /\ _).
  Fail my_context_match (_ \/ _).
  my_context_match True.
  exact (conj I I).
Qed.

open\u constr
(尽管这个5岁的孩子到今天还没有被记录在案)代替
uconstr
,这似乎效果更好,但我会让一个对Ltac的黑暗魔法更有经验的人给出答案。我不知道open\u constr。谢谢为什么您需要最后一个
idtac
?最后一个
idtac
不需要,我可能是在复制粘贴时留下的。我现在把它取下来了。