Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Class_apply and instances level

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Class_apply and instances level


Chronological Thread 
  • From: Dan Frumin <dfrumin AT cs.ru.nl>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Class_apply and instances level
  • Date: Mon, 16 Sep 2019 20:37:30 +0200
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=dfrumin AT cs.ru.nl; spf=Pass smtp.mailfrom=dfrumin AT cs.ru.nl; spf=None smtp.helo=postmaster AT smtp2.science.ru.nl
  • Ironport-phdr: 9a23:TolglBdqx520qxA+vbd6rZMxlGMj4u6mDksu8pMizoh2WeGdxcu+Zx7h7PlgxGXEQZ/co6odzbaP6Oa5AidZu8nJ8ChbNsAVDVld0YRetjdjKfbNMVf8Iv/uYn5yN+V5f3ghwUuGN1NIEt31fVzYry76xzcTHhLiKVg9fbytScbdgMutyu+95YDYbRlWizqhe7NyKwi9oRnMusUMjoZuN6g8xgHUrnZGdOha2H1kKFCOlBr4+su84YRv/itNt/4/7cJMTbn2c6ElRrFEEToqNHw46tf2vhfZVwuP4XUcUmQSkhVWBgXO8Q/3UJTsvCbkr+RxwCaVM9H4QrAyQjSi8rxkSAT0hycdNj4263/Yh8pth69Guh2hphh/w4nJYIGJMfd1Y63Qcc8GSWdHQ81cUTFKDIGhYIsVF+cPIPhWr4f9qVUNoxWxCwajC+HzxTFHnXL2wa433v49HQ3a0gEtHdQDu2nUotXvM6cSVPi4wqfSwjXFcvhY2S396JXNchAgp/GHQLV9ftffyUk1CgPFi1SQqYr+MjyJzeQBqXKb7/d6WeKpj24qsgd8qSWsyMc0koTFm4wYxk3e+Slkwos4Kse0RFN6bNK+DZdduCGXO5N1T84jWW1lvDo2xqcbtZO7fyUG0oorywDQZvGBboOG+AjsVPyLLjd9nH9leKywhxK18UW40e38U9W00E5UoiZfidnDqnEN2ALV6sebVPRx5F2h2SuV2wDV7uFIOUE0lazFJJ492rM8i5QevVnZEiPrmkj7g7Waelgl9+Sy9ujqbbXrqoeZN4BuiwH+Nqoumta4AeQ9KgUBQmab+f6h1L3m/E35Rq5HgeEtkqXDqpDaON4Xpqi9AwNNyIYs9w6/Dyu60NQfhXQIMFVFeAueg4f1P1HOPev3AOykg1WslTdr3+rJMqfgApXLNHjDka3ucaxz605Gm0IPyoVU4IsRAbUcKtryXFXwvZrWFEwXKQuxlsruDp1TzJ4bWGTHVqOXKr7XsFmg7flpOfTKYotD62W1EOQs+/O71SxxolQaZ6T8hcJGOkD9JexvJgCiWVSph94AFWkQuQ9nFL7hkxuYTHhVYyTrBv5u1nQAEIujSLz7aMW1mrXYhHWwBdtMeyZADgLUSCq6R8C/Q/4JLRmqDIphnzgDD+HzUIo9zUvorwT7xrxsI6zO52sescC72Q==

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




Archive powered by MHonArc 2.6.18.

Top of Page