Ord for partially ordered sets
wren romano
winterkoninkje at gmail.com
Sun Apr 26 01:10:15 UTC 2015
On Fri, Apr 24, 2015 at 9:06 AM, Ivan Lazar Miljenovic
<ivan.miljenovic at gmail.com> wrote:
> What is the validity of defining an Ord instance for types for which
> mathematically the `compare` function is partially ordered?
Defining Ord instances for types which are not totally ordered is *wrong*.
For example, due to the existence of NaN values, Double/Float are not
totally ordered and therefore their Ord instances are buggy. In my
logfloat package I have to explicitly add checks to work around the
issues introduced by the buggy Ord Double instance. This is why I
introduced the PartialOrd class, and I'm not the first one to create
such a class. We really ought to have an official PartialOrd class as
part of base/Prelude. The only question is whether to use Maybe
Ordering or a specially defined PartialOrdering type (the latter
optimizing for space and pointer indirection; the former optimizing
for reducing code duplication for manipulating the
Ordering/PartialOrdering types).
--
Live well,
~wren
More information about the Libraries
mailing list