Typechecker / OverloadedStrings question 7.8 vs. 7.10

Reid Barton rwbarton at gmail.com
Sun Aug 2 23:17:41 UTC 2015


On Sun, Aug 2, 2015 at 12:58 PM, Daniel Bergey <bergey at teallabs.org> wrote:

> On 2015-07-31 at 08:59, Simon Peyton Jones <simonpj at microsoft.com> wrote:
> > Daniel Bergey wrote:
> > |  How hard would it be to give a different error message instead of "No
> > |  instance ..." when the type variable is ambiguous?  I always find this
> > |  error slightly misleading, since it seems to me that there are
> > |  multiple valid instances, not that there is "no instance".
> >
> > What would you like it to say?  I think it likely we could make it say
> that!
>
> Great!  I'd like it to say "Multiple instances for ..."  or "No unique
> instance for ...".  I have a slight preference for the former.
>

It may be worth noting that the existing error message is actually
technically
correct, in the sense that what would be needed for the program to compile
is exactly an instance of the form "instance Foldable t where ...". Then the
compiler would know that the ambiguity in the type variable t0 doesn't
matter.
It doesn't make any difference whether there are zero, one, or multiple
instances
of Foldable for more specific types. (Except in that if there is at least
one
such instance, then there can't also be an "instance Foldable t" assuming
that OverlappingInstances is not enabled.) Once you understand this, the
error
message makes perfect sense. But it is often confusing to beginners.

"Multiple instances for (C t)" seems bad because there might not be any
instances for C at all. "No unique instance for (C t)" is better most of
the time,
but it doesn't exactly get to the core of the issue, since there could be
just one
instance of C, for a specific type, and then it is no better than "No
instance for
(C t)". If I were to explain the situation, I would say "there is no single
instance
(C t) that applies for every type t", but it seems a bit wordy for a
compiler error...

Regards,
Reid Barton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20150802/58d42602/attachment.html>


More information about the ghc-devs mailing list