Ltac:可选参数策略

L. *_*ret 3 variadic coq ltac

我想在coq中制作一个Ltac战术,它可以采用1或3个参数.我ltac_No_argLibTactics模块中已经阅读过,但如果我理解正确,我将不得不调用我的策略:

Coq < mytactic arg_1 ltac_no_arg ltac_no_arg.
Run Code Online (Sandbox Code Playgroud)

这不是很方便.

有没有办法得到这样的结果?:

Coq < mytactic arg_1.

Coq < mytactic arg_1 arg_2 arg_3.
Run Code Online (Sandbox Code Playgroud)

Ant*_*nov 5

我们可以使用该Tactic Notation机制来尝试解决您的问题,因为它可以处理可变参数.

让我们重用ltac_No_arg并定义一个虚拟策略mytactic以用于演示

Inductive ltac_No_arg : Set :=
  | ltac_no_arg : ltac_No_arg.

Ltac mytactic x y z :=
  match type of y with
  | ltac_No_arg => idtac "x =" x  (* a bunch of cases omitted *)
  | _ => idtac "x =" x "; y =" y "; z =" z
  end.
Run Code Online (Sandbox Code Playgroud)

现在让我们定义上述战术符号:

Tactic Notation "mytactic_notation" constr(x) :=
  mytactic x ltac_no_arg ltac_no_arg.
Tactic Notation "mytactic_notation" constr(x) constr(y) constr(z) :=
  mytactic x y z.
Run Code Online (Sandbox Code Playgroud)

测试:

Goal True.
  mytactic_notation 1.
  mytactic_notation 1 2 3.
Abort.
Run Code Online (Sandbox Code Playgroud)