<div dir="ltr"><div>Hi Daniel,</div><div><br></div><div>The constraint on an instance declaration is, perhaps counterintuitively, discharged at the usage site rather than the definition site.<br></div><div><br></div><div></div><div>foo :: Show a => Wrapper a -> String</div><div>foo (Wrapper a) = show a</div><div><br></div><div>will produce the aforementioned diagnostic.</div><div><br></div><div>---<br></div><div>Victor<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 9, 2020 at 2:51 PM Daniel Díaz <<a href="mailto:diaz.carrete@gmail.com" target="_blank">diaz.carrete@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Thu, Oct 8, 2020 at 2:12 PM Henning Thielemann <<a href="mailto:lemming@henning-thielemann.de" target="_blank">lemming@henning-thielemann.de</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On Thu, 8 Oct 2020, Daniel Díaz wrote:<br>
<br>
> But now consider this instance:<br>
> <br>
> > newtype Wrapper a = Wrapper (Maybe a)<br>
> > instance Show a => Show (Wrapper a) where<br>
> >   show (Wrapper x) = show x<br>
> <br>
> This compiles just fine, despite—to my mind—suffering from the exact same problem that the "foo" function had.<br>
> Why does it work?<br>
<br>
There is an instance Show (Maybe a) in Prelude, but no instance Show <br>
(Wrapper a), so no overlapping.</blockquote><div><br></div><div>Sorry, I wasn't very clear there.</div><div><br></div><div>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.</div><div><br></div><div>And yet "foo" compiles without problem, while the typeclass method doesn't. </div><div><br></div></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>