A Fresh Look at Comparisons, Take 2
Yigal Chripun
yigal100 at gmail.com
Sun Apr 20 05:54:56 PDT 2008
Janice Caron wrote:
>> 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?
Thanks for the explanation :)
I'd prefer in that case either two boolean operators (the first
suggestion) or an opCmp that would throw an exception... (I a purist and
don't like enum return types that indicate errors...)
in any case I think all those strange !<> type comparisons should be
removed from D. they are not intuitive (at least for me).
--Yigal
More information about the Digitalmars-d
mailing list