<div dir="ltr"><div class="gmail_extra"><div>On Sat, Sep 21, 2013 at 2:21 AM, Bardur Arantsson &lt;<a href="mailto:spam@scientician.net">spam@scientician.net</a>&gt; wrote:</div><div>&gt; On 2013-09-21 06:16, Mike Meyer wrote:</div>
<div>&gt; &gt;  The single biggest gotcha is that two calculations</div><div>&gt; &gt; we expect to be equal often aren&#39;t. As a result of this, we warn</div><div>&gt; &gt; people not to do equality comparison on floats.</div>
<div>&gt; The Eq instance for Float violates at least one expected law of Eq:</div><div>&gt; </div><div>&gt;   Prelude&gt; let nan = 0/0</div><div>&gt;   Prelude&gt; nan == nan</div><div>&gt;   False</div><div><br></div><div>
Yeah, Nan&#39;s are a whole &#39;nother bucket of strange.</div><div><br></div><div>But if violating an expected law of a class is a reason to drop it as</div><div>an instance, consider:</div><div><br></div><div>Prelude&gt; e &gt; 0</div>
<div>True</div><div>Prelude&gt; 1 + e &gt; 1</div><div>False</div><div><br></div><div style>Of course, values &quot;not equal when you expect them to be&quot; breaking</div><div>equality means that they also don&#39;t order the way you expect:</div>
<div><br></div><div>Prelude&gt; e + e + 1 &gt; 1 + e + e</div><div>True</div><div><br></div><div>So, should Float&#39;s also not be an instance of Ord?</div><div><br></div><div>I don&#39;t think you can turn IEEE 754 floats into a well-behaved numeric</div>
<div>type. A wrapper around a hardware type for people who want that</div><div>performance and can deal with its quirks should provide access to</div><div>as much of the types behavior as possible, and equality comparison</div>
<div>is part of IEEE 754 floats.</div><div><br></div><div>   &lt;mike</div><div><br></div></div></div>