So just to be clear, this is purely hypothetical. Actually doing this in a backwards compatible way would be difficult. So this question is ignoring all of the challenges that would be involved here. My question is in a perfect world where we have acceptable solutions to all of the problems around this, would people even allow it?
The use case here is for building interesting DSLs. Here’s a random example of some code using Diesel:
let downloads = version_downloads
.filter(date.gt(now - 90.days())
.and(version_id.eq(any(versions))
.or(something_else))
Compared with
let downloads = version_downloads
.filter(date > (now - 90.days())
&& version_id == any(versions)
|| something_else)
(or slightly more conservatively)
let downloads = version_downloads
.filter((date > (now - 90.days()))
.and(version_id == any(versions))
.or(something_else))
It seems from the outside like the reason Eq and Ord don’t allow overloading the return types is so that we can define ne in terms of eq, and gt, lt, gte and lte in terms of cmp, not because there was fundamental opposition to them returning types other than bool.
Again, I don’t want to focus on how we would go about implementing overloaded return types, but more just curious how people would feel about it if it were allowed at all.