Ltac:从名字

时间:2017-06-29 08:53:02

标签: pattern-matching coq ltac

我正在寻找一种方法,通过它的名字得到一个hypotesis以匹配它。像这样:

Ltac mytactic h_name :=
let h := hyp_from_name h_name in
    match h with
    | _ /\ _ => do_something
    | _ => print_error_message
    end
.

将使用这样的:

H0 : A /\ B
==================
A

Coq < mytactic H0.

感谢。

1 个答案:

答案 0 :(得分:3)

我不确定我完全理解你的问题,但我会尝试。您可以使用type of <term>结构,如下所示:

Ltac mytactic H :=
  match type of H with
  | _ /\ _ =>
    let H1 := fresh in
    let H2 := fresh in
    destruct H as [H1 H2]; try (inversion H1; inversion H2; subst)
  | _ => fail "Algo salió mal, mi amigo"
  end.

Example por_ejemplo x : x >= 0 /\ x <= 0 -> x = 0.
Proof.
  intros H.
  now mytactic H.
Qed.