July 19, 2018
On Wednesday, 18 July 2018 at 17:30:21 UTC, Jonathan M Davis wrote:
> On Tuesday, July 17, 2018 21:18:12 John Colvin via Digitalmars-d wrote:
>> Just do what std.typecons.Proxy does and return float.nan for the incomparable case.
>
> Since when is that legal? I thought that it was required for opCmp to return int. Certainly, the spec implies that it has to be int. The fact that the compiler allows it seems like a bug, though if Phobos is doing it, it wouldn't surprise me if Walter would choose to update the spec rather than fixing the compiler.

It always worked with float as returntype (at least since I'm using D
- about 2.40 or so?), and it was necessary for the (unfortunately
deprecated) special operators <>, !<>, <>=, !<>=, ...

would really pissing me off if someone deemed this excellent feature
beeing a bug and removed it. The OP already found out that some
valuable mathematical concepts doesn't work with only 3 values for
opCmp. The 4th value is essencial.

July 19, 2018
On Wednesday, 18 July 2018 at 17:49:19 UTC, H. S. Teoh wrote:
> On Wed, Jul 18, 2018 at 11:30:21AM -0600, Jonathan M Davis via On the other hand, if opCmp is allowed to return a user-defined type, it would solve the problem in a neat way: just define a quaternary type that encapsulates the values -1, 0, 1, NaN, and have opCmp return the equivalent of NaN for non-comparable arguments.  Then we could support partial orders correctly.
>
> But I have a hard time seeing this actually work in practice, because a user-defined return type for opCmp leads to recursion:
It already works with float, no recursion. A lot of the types I use depend on this.

But having a language supported quarterny type would be good for its improved speed.

July 19, 2018
On Thursday, 19 July 2018 at 10:14:34 UTC, Dominikus Dittes Scherkl wrote:
> On Wednesday, 18 July 2018 at 17:30:21 UTC, Jonathan M Davis wrote:
>> On Tuesday, July 17, 2018 21:18:12 John Colvin via Digitalmars-d wrote:
>>> Just do what std.typecons.Proxy does and return float.nan for the incomparable case.
>>
>> Since when is that legal? I thought that it was required for opCmp to return int. Certainly, the spec implies that it has to be int. The fact that the compiler allows it seems like a bug, though if Phobos is doing it, it wouldn't surprise me if Walter would choose to update the spec rather than fixing the compiler.
>
> It always worked with float as returntype (at least since I'm using D
> - about 2.40 or so?), and it was necessary for the (unfortunately
> deprecated) special operators <>, !<>, <>=, !<>=, ...

The oldest reference to opCmp returning NaN that I've found is from 2005, so it's not an entirely new thing:
https://forum.dlang.org/thread/dd3cea$26u7$1@digitaldaemon.com

--
  Simen
1 2
Next ›   Last »