A Fresh Look at Comparisons, Take 2
Janice Caron
caron800 at googlemail.com
Fri Apr 18 06:30:12 PDT 2008
I'm not clear on whether one needs partial ordering built into a
programming language. Certainly partially ordered sets exist in
mathematics. For example, consider the set of four points P = { a, b,
c, d }, defined such that
a < b < d
a < c < d
but where b cannot be compared with c (a diamond-shaped arrangement).
If D fully supported partially ordered types, then we would have
(b < c) == false
(b > c) == false
(b <> c) == false
(b == c) == false
and elements of type P could not be AA keys. The question is, does D
need to support this at the level of built-in comparisons? After all,
one could easily bolt that sort of thing on afterwards as a bunch of
plain functions, e.g.
class P
{
bool partialLess(P p) {...}
bool partialGreater(P p) {...}
}
for those classes that need it. Library solutions such as
std.algorithm may be able to accept partially ordered sets where
appropriate. But I think that it's such a rare edge-case that having
it built into the language itself is probably unnecessary. After all,
we don't have that now, and I've never seen a complaint about its
absence.
More information about the Digitalmars-d
mailing list