Typechecker / OverloadedStrings question 7.8 vs. 7.10
Reid Barton
rwbarton at gmail.com
Mon Aug 3 17:19:56 UTC 2015
On Mon, Aug 3, 2015 at 12:43 AM, Phil Ruffwind <rf at rufflewind.com> wrote:
> I think the error message could be made clearer simply by emphasizing the
> fact
> that type ambiguity over the lack of instances.
>
> Ambiguous type variable 't0' arising from a use of
> elem :: a -> t0 a -> Bool
> caused by the lack of an instance 'Data.String.IsString (t0 Char)'
> Either add a type annotation to dictate what 't0' should be
> based on one of the potential instances:
> instance Foldable (Either a) -- Defined in ‘Data.Foldable’
> instance Foldable Data.Proxy.Proxy -- Defined in ‘Data.Foldable’
> instance GHC.Arr.Ix i => Foldable (GHC.Arr.Array i)
> -- Defined in ‘Data.Foldable’
> ...plus three others)
> or define the required instance 'Data.String.IsString (t0 Char)'.
>
I like this style of error message since it points to the most likely fix
first.
If there are no "potential instances" (instances for specializations of the
type we need an instance for) in scope, then we can produce the old
"No instance for C t0" error, which suggests that the user write (or import)
such an instance. If there is at least one "potential instance" in scope,
then (assuming that the user wants to keep their existing instances,
and not use overlapping instances) they in fact must specify the type
variable somehow.
The only case that may still cause confusion is when there is exactly one
"potential instance" in scope. Then the user is likely to wonder why the
type is ambiguous. It might help to phrase the error message text in a
way that implies that the list of instances it displays is not necessarily
exhaustive.
Regards,
Reid Barton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20150803/6e461475/attachment-0001.html>
More information about the ghc-devs
mailing list