代码之家  ›  专栏  ›  技术社区  ›  Siddharth Bhat

关于类型类实例的推理在一个定理中得到了应用?

  •  0
  • Siddharth Bhat  · 技术社区  · 7 年前
    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 一切都会好起来的。但现在,我不能这样做。

    但是,我如何说服COQ ACT=施工 在这种情况下?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Siddharth Bhat    7 年前

    我在另一条so线索上找到了答案: Coq: unfolding typeclass instances

    Proof 带A的节 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.