Ltac:可选参数策略

时间:2017-06-30 07:10:21

标签: coq variadic ltac

我想在coq中制作一个Ltac策略,它可以采用1或3个参数。我在LibTactics模块中已经阅读了ltac_No_arg,但如果我理解正确,我将不得不用以下方式调用我的策略:

Coq < mytactic arg_1 ltac_no_arg ltac_no_arg.

这不太方便。

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

Coq < mytactic arg_1.

Coq < mytactic arg_1 arg_2 arg_3.

1 个答案:

答案 0 :(得分: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.

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

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.

试验:

Goal True.
  mytactic_notation 1.
  mytactic_notation 1 2 3.
Abort.
相关问题