coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Cao Qinxiang <caoqinxiang AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Class_apply and instances level
- Date: Tue, 17 Sep 2019 13:56:52 +0800
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=caoqinxiang AT gmail.com; spf=Pass smtp.mailfrom=caoqinxiang AT gmail.com; spf=None smtp.helo=postmaster AT mail-oi1-f174.google.com
- Ironport-phdr: 9a23:AjDFKBLG3VK0VVUJMNmcpTZWNBhigK39O0sv0rFitYgRL/7xwZ3uMQTl6Ol3ixeRBMOHsqkC0rad6vi6ESxYuNDd6SpEKMQNHzY+yuwu1zQ6B8CEDUCpZNXLVAcdWPp4aVl+4nugOlJUEsutL3fbo3m18CJAUk6nbVk9Kev6AJPdgNqq3O6u5ZLTfx9IhD2gar9uMRm6twrcutQYjId4N6o8xRTFrmZUd+hI2GhkIU6fkwvm6sq/4ZJv7T5ct+49+8JFTK73Y7k2QbtEATo8Lms7/tfrtR7NTQuO4nsTTGAbmQdWDgbG8R/3QI7/vjP1ueRh1iaaO9b2Ta0vVjS586hrUh7ohzwZODM/7Wral9Z/jKNfoBKmuhx/34vZa5ybOfZiYq/Qe84RSGxcVchTSiNBGJuxYIQBD+UDPehWoYrzqUYQoxSiHgSjHv/jxyVSi3PqwaE30eIsGhzG0gw6GNIOtWzZocvvO6cVTOu716jIzTPMbvNXwzj97ofIeQ0mrP6QR71wdtPRyUgpFwLKj1Wfs4rlPzyO2+QCtmiU9etgVea1h2E7rAFxpyGiy8ExgYfKnoIY0k7I+Tl9zYovJtC1SFR3bcOlHZZSrS2WKol7T8wkTmp1oig10KcGtoS+fCUSyJQo2Rrfa/uffoiN+B3jVeKRLS5/hHJkZb6znhiy/VWix+DzTMW031FKri1KktnIqH8BzQDc6s+CSvdl/0eh3yiA1xzL5+1aPUw5kbDXJp0hz7Iqi5YesEbOEjXrlEj0g6KabkAk9fKp6+TjbLXmvJicN4pshw7iKKsundW/AeU+MgkBXmiU4+K81LL48E32RbVFlPw2kq3DvJ/GIsQbo7a1AxVJ3YY79xa/EzCm3cwEknkANVJJYQ6Ij4z0O17VO/34Fve+g1G0kDhx3fzGP7vhAo/MLnfZirvhc6x9uAZgz184yska7JZJAJkAJujyUwn/ro/2FBg8Zie9xK7eCdNt14oYVirbCaaeKaLUoV6B4O0HLOyFZYtTszH4fat2r8XyhGM0zAdONZKi2oEaPSjhQqZWZn6BaH+pue8vVH8Qt1NnHuPvgVyGFzVUYiTqBv9u1nQAEIujSLz7aMWtjbiGhnnpG5RXYiVBCwnJHy63K8OLXPADbC/UKchkwGRdBOqRDrQ53BTrjzfUjr9uL+7a4Cod7Mux29185umVnhY3p2V5
Dear Dan,
Thank you very much!
Best,
Qinxiang
On Tue, Sep 17, 2019 at 2:37 AM Dan Frumin <dfrumin AT cs.ru.nl> wrote:
Dear Qinxiang Cao,
I don't know an answer to your first question, but as for the second one, I believe that the default priority for an instance is the number of its
arguments that are not (formally) dependant on the other arguments. So, in your case Foo1Prod has priority 2 (arguments A and B). foo1 on the other
hand has default priority of 1. That explains the Coq behavior in your snippet.
Best,
Dan
On 16-09-19 08:40, Cao Qinxiang wrote:
> Dear Coq clubbers,
>
> Here are two questions about coq type classes.
>
> 1. I find this line of code in standard library (Coq.Classes.RelationClasses):
> Hint Extern 1 (Reflexive (complement _)) => class_apply @irreflexivity : typeclass_instances.
> But what does "class_apply" mean? What is the difference between "class_apply" and "apply"? I cannot find it in Coq's tactic index.
>
> 2. When declaring instances using "Existing Instance", I can provide a priority number. Smaller numbers have high priority. But what is the order
> between instances with a priority number and those without a priority number? The following examples seem to say: there is not such thing called
> default priority number.
>
> Class Foo1 (A: Type): Type.
> Class Foo2 (A: Type): Type.
>
> Class Foo (A: Type): Type := {
> foo1 : Foo1 A;
> foo2 : Foo2 A
> }.
> Definition FooProd {A B: Type} {FooA: Foo A} {FooB: Foo B}: Foo (A*B).
> constructor; constructor.
> Qed.
>
> Definition Foo1Prod {A B: Type} {FooA: Foo1 A} {FooB: Foo1 B}: Foo1 (A*B).
> constructor.
> Qed.
>
> Set Printing All.
>
> Module DefaultBeforeOne.
>
> Local Existing Instance FooProd | 1.
> Local Existing Instance Foo1Prod | 1.
> Local Existing Instance foo1 .
> Local Existing Instance foo2 .
> Goal forall (A B: Type) (FooA: Foo A) (FooB: Foo B), Foo1 (A * B).
> Proof.
> intros.
> eauto with typeclass_instances.
> Qed.
>
> Print Unnamed_thm.
>
> End DefaultBeforeOne.
>
> Module DefaultAfterTwo.
>
> Local Existing Instance FooProd.
> Local Existing Instance Foo1Prod.
> Local Existing Instance foo1 | 2.
> Local Existing Instance foo2 | 2.
> Goal forall (A B: Type) (FooA: Foo A) (FooB: Foo B), Foo1 (A * B).
> Proof.
> intros.
> eauto with typeclass_instances.
> Qed.
> Print Unnamed_thm.
>
> End DefaultAfterTwo.
>
> Module DefaultBeforeThree.
>
> Local Existing Instance FooProd.
> Local Existing Instance Foo1Prod.
> Local Existing Instance foo1 | 3.
> Local Existing Instance foo2 | 3.
> Goal forall (A B: Type) (FooA: Foo A) (FooB: Foo B), Foo1 (A * B).
> Proof.
> intros.
> eauto with typeclass_instances.
> Qed.
> Print Unnamed_thm.
>
> End DefaultBeforeThree.
>
>
> Thank you very much!
>
> Best regards,
> Qinxiang Cao
> Shanghai Jiao Tong University, John Hopcroft Center
> Room 1110-2, SJTUSE Building
> 800 Dongchuan Road, Shanghai, China, 200240
>
- [Coq-Club] Class_apply and instances level, Cao Qinxiang, 09/16/2019
- Re: [Coq-Club] Class_apply and instances level, Dan Frumin, 09/16/2019
- Re: [Coq-Club] Class_apply and instances level, Cao Qinxiang, 09/17/2019
- Re: [Coq-Club] Class_apply and instances level, Dan Frumin, 09/16/2019
Archive powered by MHonArc 2.6.18.