[erlang-questions] strictly less-than (Re: [erlang-questions] Ordered set and DETS)

Richard O'Keefe <>
Fri Sep 10 04:27:48 CEST 2010


On Sep 9, 2010, at 11:34 PM, Jesper Louis Andersen wrote:
> Fun aside relating to this point: Standard ML defines specific types
> as eqtypes or types which can be compared for equality. The 'real'
> type of ML is not an eqtype because of the above mentioned trouble:
> comparing two reals (IEEE FPs) for equality is almost often wrong.

I see this claim a lot, but I wonder how true it is.
In *beginners'* code, yes, sure, but then, almost everything in
beginners' code is wrong at some point.

Attempts to deal with the problem by banning = don't really help,
because you can always define
	fun eql x (y:float) = not (x < y orelse x > y);
after which eql 0.0 ~0.0 is not only defined but true.

If it comes to that, the MLton compiler complains every time you
use polymorphic equality at all.

> The MosML implementation of SML get this wrong and allows reals to be
> compared for equality. This also means that programs which compile in
> MosML does not compile in other SML implementations. It has bitten me
> more than once.

ocaml also does this.



More information about the erlang-questions mailing list