Typechecker / OverloadedStrings question 7.8 vs. 7.10

Daniel Bergey bergey at teallabs.org
Mon Aug 3 16:45:34 UTC 2015


On 2015-08-02 at 23:17, Reid Barton <rwbarton at gmail.com> wrote:
> 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.

I thought GHC would infer the type when only one instance is in scope,
at least in some cases, like IsString.  But I could well be wrong about that.

> But it is often confusing to beginners.

I think it is beginners who are most affected by the wording of error
messages.  With time, the errors are familiar - I know how I fixed the
last dozen similar errors, and can fix the next one the same way.  But
for beginners, the messages serve as explanations of what is wrong, and
they ought to be worded to make sense to beginners.  

> "Multiple instances for (C t)" seems bad because there might not be any
> instances for C at all.

My initial question was whether GHC can give a different message when
there are multiple instances than when there is none.  I appreciate your
point that these are not so different, but that's an insight that helps
me today, not a Haskell newcomer I was several years ago.  (Though GHC
today lists several matching instances, which is a great improvement
over the behavior in 7.4 when I was learning this.)

> "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


More information about the ghc-devs mailing list