[Haskell-cafe] Monad laws

Mike Meyer mwm at mired.org
Sun Jun 29 09:53:03 UTC 2014


On Sun, Jun 29, 2014 at 4:28 AM, <ok at cs.otago.ac.nz> wrote:

> On the subject of Double and laws, I imagine it would have been
> possible to do the kind of thing the SML Basis Library does for
> equality.  SML spells equality '=' and it's not defined on the
> floating point types, which have a *different* operator, '=='.
>


If you do that, where do you stop? Not all Int's have additive inverses,
and most floats have multiple things they can be added to that don't change
their value. Can we call both of those +? Or do we need a name for them or
two?

Actually, I don't know if SML got it right or not, because I don't know
what the "==" operator does. But you should *never* compare floats for
equality. While there are exceptions, they are so rare that you're likely
never to run into one, so just be safe, and don't do it.

So if SML's "==" operator is an equality comparison, they at best got it
half right. If it's some kind of programmer-controlled "fuzzy equality",
well, maybe. But I think just leaving it out would be a better solution.

In the same way, the Prelude could have been structured so that
> integers and ratios belonged to Ord but floats did not.  Floats
> could have had operators like #< #= instead.  It would have been
> surprising, but so is x == x being False surprising.
>

Is x == x being false really any more surprising than x + 1  == x being
true?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140629/79d78c06/attachment.html>


More information about the Haskell-Cafe mailing list