Proposal: New Eq and Ord instances for Double and Float
wren ng thornton
wren at freegeek.org
Tue Sep 27 07:56:38 CEST 2011
On 9/26/11 1:05 AM, Bryan O'Sullivan wrote:
> On Sun, Sep 25, 2011 at 10:53 PM, Daniel Fischer<
> daniel.is.fischer at googlemail.com> wrote:
>> Proposal: Provide Double and Float with Eq and Ord instances that introduce
>> a total order.
> I am strongly against this proposal, as it is in an area that is
> particularly poorly understood by most programmers (even experts). While the
> current behaviour may be undesirable from some points of view, at least it
> is consistent with most other programming languages - and this is one of the
> few areas where I think that's important.
I am also opposed to this proposal. I agree that the current situation
is problematic, however I do not see this proposal as an improvement.
Actual improvements would be to:
(a) distinguish classes for semantic ordering vs arbitrary ordering,
where the latter is used by Data.Map and friends, whereas the former is
used whenever we expect the results to be meaningful; or
(b) distinguish classes for partial orders vs total orders, either as is
done in the logfloat package, by flattening the (Maybe Ordering)
representation if people find that preferable, or by figuring out some
better theory/combinators for partial orders.
In either case, Double/Float will not have instances for Ord because
these types do not have a semantic total ordering. Moreover, the current
proposal grossly violates the principle of least surprise (for new
users) and is guaranteed to introduce subtle and obscure bugs (for old
users) since we cannot detect where the old behavior is being relied
upon, either explicitly or implicitly.
More information about the Libraries