我想写一个带有可选变量名的策略。原来的战术是这样的:
Require Import Classical.
Ltac save :=
let H := fresh in
apply NNPP;
intro H;
apply H.
我想让用户有机会选择他想要的名称并使用它:save a
例如。
我使用此解决方案编写了一个变体:
Require Import Classical.
Inductive ltac_No_arg : Set :=
| ltac_no_arg : ltac_No_arg.
Ltac savetactic h :=
match type of h with
| ltac_No_arg => let H := fresh in
apply NNPP;
intro H;
apply H
| _ => apply NNPP;
intro h;
apply h
end.
Tactic Notation "save" := savetactic ltac_no_arg.
Tactic Notation "save" ident(x) := savetactic x.
然而,这个证明失败了save h
:
Lemma te (A B : Prop) : A \/ ~A.
Proof.
save h.
right.
intro a.
apply h.
left.
exact a.
Qed.
错误信息:
In nested Ltac calls to "save (ident)", "savetactic" and "h", last term evaluation failed.
In nested Ltac calls to "save (ident)", "savetactic" and "h", last term evaluation failed.
Variable h should be bound to a term but is bound to a ident.
我想我必须确保它h
是新鲜的,但我不确定如何做到这一点。