-
Notifications
You must be signed in to change notification settings - Fork 45
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
Thought: implement PartialOrd/Ord for things? #226
Comments
I'd say that's why Any use cases for having an ordering on them that is all but arbitrary? |
Thanks for tagging me, I've been toying around with this myself but the biggest question I have is: Ordering in relation to what? Because while I got the stuff to work now, using a BTreeMap for my specific purpose, the calculation for the key value is offloaded into a separate function because the ordering has to make sense(in my case, a specific point on the map and the ordering is travel distance). If you're going to order based on an arbitrary property, how useful will the ordering be? There's a pretty select set of use cases for rooms ordered by travel distance from origin (0, 0) (for instance). Wouldn't a set of structs that allow custom ordering via a closure (or similar mechanism) perhaps be more useful? |
In that case, I'd vote to make sure |
I went through the structs that we define. The only one I can see where it would make sense to add |
My main motivation is to be able to "just use" these things in Maybe that's not a very good reason to do this though? |
What if we added an ordering function (that returns a I'm not comfortable breaking the |
I think an ordering function could be good, but it could still be pretty annoying to used compared to just being able to Would we really be breaking the It does feel a bit against the spirit of PartialOrd, but I don't think that these implementations would be explicitly breaking it? With that said, I'm OK with not adding these. Does feel like lying to say that |
I've posted about this issue, but not really pitched it. I think I can do better, after thinking about it. Here's an actual use case? Right now, all constants, and things I'd really like to enable using constants in The second best way is to manually implement impl Ord for X {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(other.0).then_with(|| (self.1 as u32).cmp(other.1 as u32))
}
} Not too painful, but has boilerplate. I believe using a custom method which returns If we As I understand it, the trait contract of From a perspective ignoring sensibility of implemented traits, I would see this as a positive change. I don't want to ignore the sensibility of ordering, though. If we just stick
What would you think if instead, we introduce arbitrary but rational orderings? We could order:
These orderings are not particularly useful. However, they are logical, and reproducible in other programming languages. The string constants, the integer constants and Anyways, that's my pitch. It should be at least somewhat reasonable, and if not, at least the idea is now well documented. @ASalvail I'm hoping this address some of the reasonability of implementing PartialOrd / Ord on things which don't have a single expected ordering? |
Clearly you want this implemented more than I want it not implemented 😛 I'm good with the orderings you suggested, with one exception: for Plus, make sure to document the ordering! Do you need help for any of it? |
I mean that's fair, but I'd hope to convince you too :p. I'm glad to have gone through and thought of logical ways of doing this, in any case. Much better than my original idea of just slapping
This... is what I meant. Thanks!
Will do! I think I should be good to just implementing this, though if you'd like to I can hand off some to you? As you say though, I'm kind of the one driving this - so it seems reasonable for me to do the implementation work. |
You go ahead then. And don't worry, I am mostly convinced by the
implementations you suggested. It's better than object ids in python in any
case!
I suppose it's my background in math that pushed me to push back on any
kind of ordering on R^2.
…On Thu, Aug 22, 2019, 22:35 David Ross ***@***.***> wrote:
Clearly you want this implemented more than I want it not implemented
stuck_out_tongue
I mean *that's fair*, but I'd hope to convince you too :p.
I'm glad to have gone through and thought of logical ways of doing this,
in any case. Much better than my original idea of just slapping #[derive(PartialOrd,
Ord)] on everything.
I'm good with the orderings you suggested, with one exception: for
Position and RoomName, sort first by y, then by x (which I think is that
you meant, as it follows reading order).
This... is what I meant. Thanks!
Plus, make sure to document the ordering!
Do you need help for any of it?
Will do! I think I should be good to just implementing this, though if
you'd like to I can hand off some to you?
As you say though, I'm kind of the one driving this - so it seems
reasonable for me to do the implementation work.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#226?email_source=notifications&email_token=ABBF5FDA7GLOHC5LWMP6XYDQF5EHNA5CNFSM4IMRLLGKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD466EPI#issuecomment-524149309>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABBF5FD3F6BYZT5XQZQYZTLQF5EHNANCNFSM4IMRLLGA>
.
|
Right now, almost nothing in the library has a "natural" ordering, and thus nothing implements
Ord
.While this is reasonable, it means nothing can be stored as a key in a
BTreeSet
orBTreeMap
, which might be desireable.@ASalvail What do you think of having
Position
,RoomName
,Resource
, and all other constants which implementHash
also implementPartialOrd
andOrd
, using an arbitrary but consistent-within-releases ordering?The text was updated successfully, but these errors were encountered: