-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Ord method defaults #24
Comments
This also infinitely loops right now. Do you mean "if one defines |
Yes, I'm referring to a proper implementation of |
@treeowl if you'd like to move this forward, please link an MR. |
@treeowl just a gentle reminder that this proposal needs an MR before holding a vote. |
@treeowl unless there is a progress with your proposal within two weeks, I'll close it as abandoned. |
I'll try to do something about it this weekend. |
@treeowl just a gentle reminder. Or maybe someone else can help us to move this change to |
@Bodigrim If someone has the time, I'd be very grateful. |
Thanks @tbidne! Dear CLC members, let's vote on the proposal to express default implementations of +1 from me. |
+1 |
+1. ezpz. |
It logically makes good sense that it should be easier for the compiler to get better code out of this, but can we somehow quickly confirm that it really happens before pulling the trigger? If so, I'm +1. I really hope there are no libraries out there which would be negatively impacted by this (though if anyone has a good way to search Hackage, that'd be awesome) -- it's an easy fix in any case, but it'll be a nontermination bug that will only show up at runtime if someone really does have an offending definition. |
@cgibbard this is really about semantics, not performance. |
-1 Proposer @treeowl mentions twice that it's about performance and doesn't mention semantics in the original proposal
yet then says it's about semantics, not performance. So I'm confused and unable to see what the purported benefit is. |
Proposer will think about that again and try to remember. |
Here is a current definition of instance (Ord a) => Ord [a] where
compare [] [] = EQ
compare [] (_:_) = LT
compare (_:_) [] = GT
compare (x:xs) (y:ys) = case compare x y of
EQ -> compare xs ys
other -> other The definition of With regards to performance, the very next instance in -- We don't use deriving for Ord Char, because for Ord the derived
-- instance defines only compare, which takes two primops. Then
-- '>' uses compare, and therefore takes two primops instead of one.
instance Ord Char where
(C# c1) > (C# c2) = isTrue# (c1 `gtChar#` c2)
(C# c1) >= (C# c2) = isTrue# (c1 `geChar#` c2)
(C# c1) <= (C# c2) = isTrue# (c1 `leChar#` c2)
(C# c1) < (C# c2) = isTrue# (c1 `ltChar#` c2) Under the proposal it would be enough to define @tomjaguarpaw @cgibbard does it help? |
@cgibbard does my explanation help to convert your conditional vote into an unconditional one? |
+1 I change my vote. Thanks @Bodigrim, your explanation shows that the merit of this change with respect to performance. (For posterity: This will help get better performance by default, which is great, but I still remain somewhat skeptical of the robustness of relying on default methods if you want good performance.) |
OK, this gives us at least 4 votes in favor. Approved, thanks all. |
I'm trying to summarise the state of this proposal as part of my volunteering effort to track the progress of all
Please, let me know if you find any mistakes 🙂 |
Currently,
Ord
is definedThe note about defining
max
andmin
using<=
rather thancompare
actually applies to the other methods too. I propose we redefine them thus:With these changes, no one should ever have to define a custom
>=
,>
, or<
to get optimal performance in optimized code.What can go wrong? If someone defines
<=
in terms of either>=
,>
, or<
, and lets the latter have its default implementation, then they'll end up in an infinite loop. This seems fairly unlikely to me, since there's absolutely no reason for anyone to do that.Note that in some cases, certain methods may get lazier. Suppose we have
<=
is lazy in its second argument:Z <= undefined = True
. With the current defaults, all the other comparison methods are strict. However, with the proposed defaults,>=
and<
will be lazy in their second argument and>
will be lazy in its first argument.The text was updated successfully, but these errors were encountered: