[Haskell-cafe] Overlapping instances: are functions and typeclass methods treated differently?
Daniel Díaz
diaz.carrete at gmail.com
Fri Oct 9 12:49:49 UTC 2020
On Thu, Oct 8, 2020 at 2:12 PM Henning Thielemann <
lemming at henning-thielemann.de> wrote:
>
> On Thu, 8 Oct 2020, Daniel Díaz wrote:
>
> > But now consider this instance:
> >
> > > newtype Wrapper a = Wrapper (Maybe a)
> > > instance Show a => Show (Wrapper a) where
> > > show (Wrapper x) = show x
> >
> > This compiles just fine, despite—to my mind—suffering from the exact
> same problem that the "foo" function had.
> > Why does it work?
>
> There is an instance Show (Maybe a) in Prelude, but no instance Show
> (Wrapper a), so no overlapping.
Sorry, I wasn't very clear there.
The problem is not with the "Show (Wrapper a)" instance itself, but with
its implementation of "show". It depends (just as the function "foo" did)
on "Show (Maybe a)", for which there are overlapping instances.
And yet "foo" compiles without problem, while the typeclass method doesn't.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20201009/ea4d7a9f/attachment.html>
More information about the Haskell-Cafe
mailing list