关于在一个定理中被提到的类型类实例的推理?

时间:2018-06-16 16:25:46

标签: coq coq-tactic

Class Action (Actor: Type) (Acted: Type) :=
  {
    act : Actor -> Acted -> Acted;
    someProof: forall (a: Actor), a = a;
  }.

Instance natListAction: Action nat (list nat) :=
  {
    act (n: nat) (l: list nat) := cons n l;
  }.
Proof.
    auto.
Qed.


Lemma natListAction_is_cons: forall (n: nat) (l: list nat),
    act n l = cons n l.
Proof.
  intros.
  unfold act.
  (** I cannot unfold it, since I have someProof.
   If I remove this, this unfold works **)
  unfold natListAction.
Abort.

我真正想要的是:因为我知道act解析为natListAction,我知道act = cons。因此,引理应该通过。

如果我的someProof课程中没有Action,那么我可以unfold natListAction并且其工作正常。但现在,我无法这样做。

但是,如何在这种情况下说服act = cons的coq?

1 个答案:

答案 0 :(得分:0)

我在另一个SO帖子上找到答案:Coq: unfolding typeclass instances

使用Proof结束Qed部分会使其不透明。相反,用Defined结束证明,它将通过。

为了完整起见,这是最后的证明:

Class Action (Actor: Type) (Acted: Type) :=
  {
    act : Actor -> Acted -> Acted;
    someProof: forall (a: Actor), a = a;
  }.

Instance natListAction: Action nat (list nat) :=
  {
    act (n: nat) (l: list nat) := cons n l;
  }.
Proof.
  auto.
  (** vvv Notice the change! this is now "Defined" vvv **)
Defined.


Lemma natListAction_is_cons: forall (n: nat) (l: list nat),
    act n l = cons n l.
Proof.
  intros.
  unfold act.
  unfold natListAction.
  reflexivity.
Qed.