<div dir="ltr">The equations you've posted are laws that the instances of the Eq typeclass must satisfy. If someone creates an instance that does not satisfy all of the laws then the behavior is undefined. Laws are generally not present in the source code outside of the comments, and they typically can not be proved in standard Haskell.<div><br></div><div>I don't know why the documentation links are broken (bug in hackage?) but you can find the source links here: <a href="https://hackage.haskell.org/package/ghc-prim-0.7.0/docs/GHC-Classes.html">https://hackage.haskell.org/package/ghc-prim-0.7.0/docs/GHC-Classes.html</a><div><br></div><div>Many instances are automatically derived by the compiler (which is usually what you would do for your own data types) or are otherwise dependent on built-in primitives (e.g. eqInt, eqWord, etc.).</div><div><br></div><div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 2, 2021 at 8:38 AM Galaxy Being <<a href="mailto:borgauf@gmail.com">borgauf@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">While learning about type classes, I tried to find the actual source code for Eq. In my beginner books this much is typically given<div><br></div><div><font face="monospace">class Eq a where<br> (==), (/=) :: a -> a -> Bool<br><br>-- Minimal completion definition:<br> x /= y = not (x == y)<br> x == y = not (x /= y)</font><br></div><div><br></div><div>I then found <a href="https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-Eq.html" target="_blank">this</a> at <a href="http://hackage.haskell.org" target="_blank">hackage.haskell.org</a>, but the "source" links are dead. On this page is a section of what I can't tell is either source code or just commentary on all the different mathematical ideas about equality, i.e., </div><div><br></div><div><font face="monospace">Reflexivity<br>x == x = True<br>Symmetry<br>x == y = y == x<br>Transitivity<br>if x == y && y == z = True, then x == z = True<br>Substitutivity<br>if x == y = True and f is a "public" function whose return type is an instance of Eq, then f x == f y = True<br>Negation<br>x /= y = not (x == y)</font><br></div><div><br></div><div>I would like to know if this is indeed in the source code or if it's just a sort of commentary. It looks important. Where can I find the actual source for all these basic type classes?</div><div><br></div><div>LB</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>