A Fresh Look at Comparisons, Take 2

Janice Caron caron800 at googlemail.com
Sat Apr 19 20:51:53 PDT 2008


>  is it possible (mathematically speaking) to have only one of the
>  operators defined?

Only if you allowed opPartialLess to return three values (true, false,
and can't compare).

For a /fully/ ordered set, you only need boolean <, because you can
derive everything else. i.e.

    (a > b) == (b < a)
    (a == b) == (!(a < b || b < a))
    etc.

but what makes an ordering partial is that there may exist some
elements, x and y say, for which x and y cannot be ordered. For such
elements, neither (x < y) nor (x > y) have meaning, and both are
considered to evaluate to false (because boolean expressions must be
either true or false).

So you'd either need both opPartialLess() and opPartialGreater() being
boolean, or you'd need a single opPartialCmp() which could return an
enum { LESS, EQUAL, GREATER, UNORDERED }.

Does that make sense?



More information about the Digitalmars-d mailing list