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.