Skip to Content.
Sympa Menu

coq-club - [Coq-Club] Simplification for typeclass instances

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[Coq-Club] Simplification for typeclass instances


Chronological Thread 
  • From: Daniel Schepler <dschepler AT gmail.com>
  • To: Coq Club <coq-club AT inria.fr>
  • Subject: [Coq-Club] Simplification for typeclass instances
  • Date: Fri, 9 Sep 2016 10:09:20 -0700
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=dschepler AT gmail.com; spf=Pass smtp.mailfrom=dschepler AT gmail.com; spf=None smtp.helo=postmaster AT mail-ua0-f169.google.com
  • Ironport-phdr: 9a23:gOFiMxDYnU995pZZG50oUyQJP3N1i/DPJgcQr6AfoPdwSP7ypsbcNUDSrc9gkEXOFd2CrakV0qyI7+u5ADVIoc7Y9itTKNoUD15NoP5VtjRoONSCB0z/IayiRA0BN+MGamVY+WqmO1NeAsf0ag6aiHSz6TkPBke3blItdazLE4Lfx/66y/q1s8WKJV4Z3XzjPfgrdUz+7V2I8JJH2c06cud54yCKi0MAQ/5Ry2JsKADbtDfHzeD0wqRe9T9Nsekq7c9KXPayVa05SbtFEGZuaDhtt4XD/CPORgqX53YaTn5e0l8RW1CEv1nGWcLatTKyne5g0mHONsrvCLswRD6K7qFxSRauhj1RZBAj92SCpsV2ja9f6CmqpxFnx4POKNWZL/F+c7vZcMkySm9IX8IXXCtEVNDvJ7ATBvYMaL4L57L2oEED+F7nXVGh

When working with typeclasses, I often find myself wanting something
like a class_simpl tactic which would unfold typeclass projections and
instances (except where the instance is an atomic variable, section
hypothesis, axiom/parameter, etc.). So, for example, in this:

Require Import Morphisms.

Class Zero (A:Type) : Type :=
zero : A.

Class Plus (A:Type) : Type :=
plus : A -> A -> A.

Class Equiv (A:Type) : Type :=
equiv : A -> A -> Prop.

Notation "0" := zero.
Infix "+" := plus.
Infix "==" := equiv (at level 70).

Class Plus0L (A:Type) `{Zero A} `{Plus A}
`{Equiv A} : Prop :=
plus_0_l : forall x:A, 0 + x == x.

Instance prod_zero (A B:Type) `{Zero A} `{Zero B} :
Zero (A * B) :=
(0, 0).

Instance prod_plus (A B:Type) `{Plus A} `{Plus B} :
Plus (A * B) :=
fun p1 => let '(a1, b1) := p1 in
fun p2 => let '(a2, b2) := p2 in
(a1 + a2, b1 + b2).

Inductive prod_equiv (A B:Type) `{Equiv A} `{Equiv B} :
Equiv (A * B) :=
| pair_proper_pre : Proper (equiv ==> equiv ==> prod_equiv A B)
(@pair A B).
Existing Instance prod_equiv.
Instance pair_proper (A B:Type) `{Equiv A} `{Equiv B} :
Proper (equiv ==> equiv ==> equiv) (@pair A B) :=
pair_proper_pre A B.

Instance prod_plus0l (A B:Type) `{Plus0L A} `{Plus0L B} :
Plus0L (A * B).
Proof.
intros [a b].

Here, I would love a class_simpl tactic to do the equivalent of:
unfold equiv, plus, prod_plus, zero, prod_zero.
to convert:
0 + (a, b) == (a, b)
to:
prod_equiv (0 + a, 0 + b) (a, b)

(And then the proof would finish with:
constructor; apply plus_0_l.
Qed.
)

So, is there an existing tactic which would do this, that I'm missing?
--
Daniel



Archive powered by MHonArc 2.6.18.

Top of Page