<p dir="ltr">No, I refuse to believe that incoherent instances are actually supported. The documentation must be lying. Overlapping instances are too complicated for me to really trust. More annoyingly, their existence anywhere violates some nice properties that would otherwise hold. For instance, from</p>
<p dir="ltr">instance C a => C (Maybe a)</p>
<p dir="ltr">along with</p>
<p dir="ltr">C (Maybe Int)</p>
<p dir="ltr">you'd like to be able to conclude that</p>
<p dir="ltr">C Int</p>
<p dir="ltr">but you can't, because maybe there's a special instance for C (Maybe Int) somewhere. Overlapping instances also work fairly badly with associated types.</p>
<div class="gmail_quote">On Feb 24, 2016 10:12 PM, "Mitchell Rosen" <<a href="mailto:mitchellwrosen@gmail.com">mitchellwrosen@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I see. I did know about the specificity rule, but somehow it escaped me that the extra <font face="courier new, monospace">y := x</font><font face="arial, sans-serif"> substitution required for the second instance to match means that the first instance <i>is</i> more specific.</font><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Thanks!</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">PS - why do overlapping instances give you hives? Did you mean incoherent instances?<br></font><br>On Wednesday, February 24, 2016 at 7:07:54 PM UTC-8, David Feuer wrote:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Oddly, this message was rejected by the system. Trying again.</p>
<div class="gmail_quote">---------- Forwarded message ----------<br>From: "David Feuer" <<a rel="nofollow">david...@gmail.com</a>><br>Date: Feb 24, 2016 10:04 PM<br>Subject: Re: [Haskell-cafe] Overlapping instances<br>To: "Mitchell Rosen" <<a rel="nofollow">mitchel...@gmail.com</a>><br>Cc: "Haskell-cafe" <<a rel="nofollow">haskel...@googlegroups.com</a>><br><br type="attribution"><p dir="ltr">It's possible that GHC will backtrack with overlapping enabled (I can't remember, and overlapping instances give me hives) but it doesn't have here. The first instance is "more specific" than the second because the type variable x appears twice.</p>
<div class="gmail_quote">On Feb 24, 2016 9:49 PM, "Mitchell Rosen" <<a rel="nofollow">mitchel...@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Consider this "list membership" typeclass and two overlapping instances:<div><br></div><div><font size="2" face="courier new, monospace">class Elem (x :: k) (xs :: [k])</font></div><div><font size="2" face="courier new, monospace"><br></font></div><div><font size="2" face="courier new, monospace">instance {-# OVERLAPS #-} Elem x (x ': xs)<br>instance {-# OVERLAPS #-} Elem x xs => Elem x (y ': xs)</font><br><br>The inductive style is satisfying, but I'm struggling to understand exactly how GHC can pick one instance over the other.</div><div><br></div><div>How is a constraint like <font face="courier new, monospace">Elem Int [Int]</font><font face="arial, sans-serif"> solved? Certainly the </font><font face="courier new, monospace">Elem x (x ': xs)</font><font face="arial, sans-serif"> instance matches, with </font><font face="courier new, monospace">x = Int</font><font face="arial, sans-serif"> and </font><font face="courier new, monospace">xs = []</font><font face="arial, sans-serif">. But, the second instance is also equally valid with </font><font face="courier new, monospace">x = Int, y = Int, xs = []</font><font face="arial, sans-serif">. Even though <i>if </i>the second instance is chosen, the context cannot be satisfied (no instance for </font><font face="courier new, monospace">Elem x []</font><font face="arial, sans-serif">), it's my understanding that GHC will not backtrack once it picks an instance. And because both instances look valid to me, I don't understand why this code does not require </font><font face="courier new, monospace">IncoherentInstances</font><font face="arial, sans-serif">.</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Thanks.</font></div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a rel="nofollow">Haskel...@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="nofollow" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div>
</div>
</blockquote></div></div></blockquote></div>