Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Typeclass confusions

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Typeclass confusions


Chronological Thread 
  • From: Matthieu Sozeau <mattam AT mattam.org>
  • To: coq-club AT inria.fr
  • Cc: Gaetan Gilbert <gaetan.gilbert AT ens-lyon.fr>
  • Subject: Re: [Coq-Club] Typeclass confusions
  • Date: Sun, 25 Jun 2017 10:13:00 +0000
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mattam AT mattam.org; spf=Pass smtp.mailfrom=matthieu.sozeau AT gmail.com; spf=None smtp.helo=postmaster AT mail-vk0-f50.google.com
  • Ironport-phdr: 9a23:xMS76h3O+pN2A9QssmDT+DRfVm0co7zxezQtwd8Zse0SLvad9pjvdHbS+e9qxAeQG96KtLQc06L/iOPJYSQ4+5GPsXQPItRndiQuroEopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZvJuTyB4Xek9m72/q89pDXYQhEniaxba9vJxiqsAvdsdUbj5F/Iagr0BvJpXVIe+VSxWx2IF+Yggjx6MSt8pN96ipco/0u+dJOXqX8ZKQ4UKdXDC86PGAv5c3krgfMQA2S7XYBSGoWkx5IAw/Y7BHmW5r6ryX3uvZh1CScIMb7Vq4/Vyi84Kh3SR/okCYHOCA/8GHLkcx7kaZXrAu8qxBj34LYZYeYP+d8cKzAZ9MXXWVOXshTWCJBDI2ybJYBAfQdMutDtYbxu0EDoAGiCQWwBu7izCJDiH/s3a091uQsCQbI0xY8H9ISsHTUrcv6NLoPWu6oy6nJzCvMYOlL2Tzg74XIdwouoe2QXb1qdMrc0kwvGBnZjlWMs4PlOimZ1uMXs2iU9udtU/+khW0/qwxpvDSj2sMhhpPKi48V0FzI6zh1zYgvKdC4VEJ2Z8OvHoFKuCGALYR2R9svQ2F2tyY+zb0LoZu7czILyJQj3hLfdf+Hf5SR7hLtVOudPS10hH1ieLK4iBay9VavxvfgWcmz1VZGtitFkt/SuXARzxHf9NSLR/9n8kqi2TuDzR7f5vxKLEwulafXN4YtwrsqmZoStUTDEDX2mELzjKKOc0Ur4PSo6/jnYrXnuJCcKpV4ihr5MqUvhMOwG/k4PxMBX2ie4+u81bnj8VflT7VNi/06irPZv4zCJcQHuq65BBdY3Zok6xamFjupzNAYnWQcI19eYxKGj43pO0nUL/ziDPe/hU6skDZxyPzcML3hGMaFEn+Wm7D4OL159kR0yQwpzNkZ6YgHJKsGJafWU1PttN3VE1cCNB65yvuvXNB0yp8XXEqKC7OFOaaUtkWHsLF8a9KQbZMY7W6uY8Mu4OTj2DpgwQcQ

Yes, that's right.

On Sun, Jun 25, 2017 at 2:54 AM Benjamin C. Pierce <bcpierce AT cis.upenn.edu> wrote:
Many thanks for the detailed explanations.  So it sounds like always using the {…} syntax for instance declarations is is the simplest approach to teach to beginners (right?).

    - B


On Jun 24, 2017, at 12:33 PM, Matthieu Sozeau <mattam AT mattam.org> wrote:

Hi, 

  indeed you're hitting a few confusing things. First the record notation:
Instance has a special syntax [{ foo := bar }] for giving the fields of the class,
while [{| foo := bar |}] was introduced after for introducing values in general record types (parsing
issues prevented to reuse simple braces { }).
 
  There is a discrepancy in how these are typechecked currently: in the Instance : C args := { ... }
case, the type information flows from the arguments of the class type constraint to the parameters
of the constructor, hence you get a typing constraint for your method which readily mentions
bool and eqBool and typechecking succeeds. 

  In the case of {| |}, the record value is typechecked  independently of the typing constraint first, 
and in your example this involves a unification problem 

  forall (x y : ?A) (_ : @eq bool (@eqb ?A ?H x y) true), @eq ?A x y ~= 
  forall (a b : bool) (_ : @eq bool (Bool.eqb a b) true), @eq bool a b

which fails at first. We try to launch typeclass resolution to fill the holes, finding ?A to be nat, 
?H to be eqNat and then the unification fails again as we chose the wrong instance. 

  Bidirectional typechecking making the typing constraint information flow to the parameters, 
avoiding this unexpected behavior, is not on by default (for compatibility reasons mainly), but activated
in Program mode, so this works too:

Program Instance eqdecBool : @EqDec bool eqBool := 
  {|
    eqb_leibniz := Bool.eqb_prop
  |}.       

Sorry for the long explanation... it's definitely confusing.
-- Matthieu

On Sat, Jun 24, 2017 at 5:43 PM Emilio Jesús Gallego Arias <e AT x80.org> wrote:
Gaetan Gilbert <gaetan.gilbert AT ens-lyon.fr> writes:

> You mean the error gotten by reverting
> a7ea32fbf3829d1ce39ce9cc24b71791727090c5 is in this case better?

Well, certainly I can't make sense of what that commit means.

Looking at the changes and commit message, it looks like the commit was
unfinished, maybe it slipped-in accidentally?

In fact it was coming from a 8.5 merge it seems, so that could explain
it.

E.




Archive powered by MHonArc 2.6.18.

Top of Page