-
Notifications
You must be signed in to change notification settings - Fork 90
Clarify relationship between Eq and Ord #174
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
Comments
You don't think it's kinda implied by the use of equals/less-than-or-equals in the laws? I suppose they don't have to be related, strictly speaking, it's more that every |
No, because Maybe you could argue that the |
Would it make sense to replace |
I think it just turns it from a total order on your type to a total order on equivalence classes on your type. |
I guess what I'm saying is, does it ever make sense for the |
I can't think of one either. |
I'm not sure what the next action is for this issue. |
I think a good next step would be to take @hdgarrood 's suggestion and simply change "=" to "==" in the laws. @hdgarrood says "does it ever make sense for the I think we can ask a stronger question: "does it make sense to force the There are various types one might want to define with both an non-trivial We can write an In some ways this feels like a very minor change to a comment. But it would be good to clear up and I don't see any argument in favor of the status quo. And, for once, it wouldn't be a breaking change. Any objections? (To add a note of caution to an otherwise strident comment, I'm assuming here that |
For what it's worth, the corresponding I don't have any objections to this because I can't think of an example against it either. That being said, if eqDefault :: forall a. Ord a => a -> a -> Boolean
eqDefault l r = l <= r && r <= l That being said, would there be any problems with the below code, where the data SomeType = ...
instance Eq SomeType where
eq = eqDefault
derive instance Ord SomeType |
Empirically, that seems to work, although I'm not completely sure of the details. One could also just define:
This prompts the question: what do the laws of PR incoming. |
Just a thought but this implementation eqDefault :: forall a. Ord a => a -> a -> Boolean
eqDefault l r = compare l r == EQ would reject cases where |
I think I imagine that the laws, as stated in terms of
If I assume (because Wikipedia says so) that the laws we have on
Hopefully, that will clarify what's going on here and maybe we can think again about the best way to document But in the short-term I think we can just make that simple change in the PR and close this issue. |
|
Closed by #298. |
Currently the docs say:
Eq
is required, but there's nothing else that says why or howOrd
andEq
are related.The text was updated successfully, but these errors were encountered: