-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rename Option
, add Assert
trait
#328
Rename Option
, add Assert
trait
#328
Conversation
I very much agree that the name of Option can be improved. Optional is marginally better, but Maybe is the best in my opinion. While I love Haskell, I think Yes and No variants may be more practical than Just and Nothing. Hopefully it can be considered regardless of whether or not the Assert trait proposal is accepted (I agree with that one as well), or are they intentionally tied together? For what it's worth, Scala also uses the same name and variants as current Rust. |
Yes/No is appropriate for a boolean value, not Option: there is no particular reason why "Yes" should carry a value, while there is for "Some" (if you have "some", what do you have?), and likewise for No vs None. I think "Something(x)" and "Nothing" would be even better, but it's much longer. |
I'm for the status-quo. An option type indicates the presence or absence of a value - it has the 'option' of being there or not. As you can see from the linked Wikipedia page, most languages use some variant of The way I see it, there are only two real contenders here that will make the least waves in terminology - |
I am also for I still think that I don't see why I like the idea of abstracting over "failing things" but this is not really unifying in the sense that I'm exceedingly unlikely to write functions which take This seems to be a rather large problem to me - HKT will likely change pervasive APIs that we would like to stabilize, like |
// for use directly | ||
trait Assert: AssertMsg { | ||
fn assert(self) -> Value { | ||
self.assert_msg("assertion failed", &(file!(), line!())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file!()
, line!()
calls here are pretty useless, aren't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. But you were never going to get an informative message here anyways (and assert_msg
expects them). For comparison, if I had directly used fail!()
here, it would have the same effect w.r.t. file/line numbers.
@bjz Apparently you are not one of those, such as I, who have always been deeply dissatisfied with the existing names for these constructors (variants), in any language. But also, @bill-myers, @bjz, and @reem, you are missing the whole point. The point is that (This is also the answer to @blaenk's question: once you accept that these types are inextricably related, it also becomes much more obvious why extending the concept of asserting from
Of course. That is why I'm trying to marshall arguments to persuade you. (In this case, we are not so much renaming
The second one will give you a better error message, due to the magic of macros, just like
Yes, I will cop to the fact that this is overloading mainly intended for the monomorphic case. (However, it occurs to me that perhaps the methods could all be formulated in terms of the
I think these are independent.
Yeah. This is actually a much more pervasive problem, which arises for essentially every major language feature we might ever want to add: they all have an impact on how standard APIs would be formulated. If they didn't, they wouldn't be major. I don't see any sane solution to this dilemma other than to version the standard library as new features become available. (But it's even worse when lang items are implicated, which they often are.) |
The changes here are for the better. |
I'm definitely against |
Then I'm hopeful that you have a compelling rebuttal to the arguments I've made? At the risk of being blunt: the likely reason why it feels like they "don't fit" is that they have a very different connotation from the existing names, which we are accustomed to, and which therefore feel "natural". Our impulse is to perfect the existing names, and not to go in a direction that's different. But if we already had an established set of names Also, |
I really don't see why Yes/No is a better analogue to true/false and Ok/Err than Some/None is. |
Compelling? No. But it's pretty clear that a |
Thank you. I agree that taken in isolation, In the context of I think there's also no intrinsic reason why we would assume that |
At minimum I think these should be split into two different RFCs so that we can consider the Assert proposal without heavy bike-shedding on something as huge as changing the name and variants of Option. On the Assert proposal, on a second read-through I'm really not convinced of the utility of this thing. Your example snippet is: let entry = map.find(key);
assert!(entry.is_some());
forbinate(entry); and that it would be replaced with: forbinate(assert!(map.find(key))); However, this looks like a straw man to me - it is certainly not idiomatic rust to forbinate(map.find(key).unwrap()) which will yield an error message with exactly the same utility as the one you get using forbinate(map.find(key).expect(format!("No key {}", key))); which yields a much better error message, or like either of these: match map.find(key) {
Some(entry) => forbinate(entry),
None => // deal with failure
}
map.find(key).map(forbinate).unwrap() // or expect, or match, or ignore it. In short, I just see limited additional utility in the new assert as opposed to using any existing tools. |
I completely agree with this. I've noticed this kind of recognition/realization multiple times with various other topics (see collections reform RFC for example). It really makes me wish HKT were targeted for 1.0. I do have to agree with @kaisellgren, match x {
No => ...
_ => ...
} Sure, this is probably unlikely to occur given something like Another pair of variants I've come up with is match my_map.find(name) {
Present(entry) => display(entry),
Absent => println!("Not found!")
} That said, I think @glaebhoerl specifically intends to make them I do think that |
I also completely agree with this. I prefer I need to look at the details such as two-traits and |
The |
A simple lookup with What's the value for the key But with renamed variants, it reads differently: Does the map contain a value for the key This renaming wouldn't be a good fit for a declarative style where values usually aren't answers to questions. |
I want to clarify this point in particular, because I think it's pretty important. Over the past couple of months, we've been carefully considering various API stabilization needs and the way they interact with language features -- and that was one of the main reasons that we decided to pursue multidispatch and associated items prior to 1.0. However, HKT is going to be a significant undertaking, and we can largely work around its absence for now by focusing primarily on "concrete" APIs, rather than highly-generic (abstract) programming through traits. We've also been thinking hard about the migration path from concrete to abstract, to make sure that we'll be able to add traits using HKT later on, without breaking compatibility or leaving around a lot of junk. That's the direction taken by the collections reform RFC, it's what we're starting to look at for Put differently, I don't think that HKT will change concrete APIs, but will rather provide a means of generically programming over them. The best thing we can do now to anticipate that future is to ensure as much consistency across APIs as we can, and to avoid settling on traits that are best expressed using HKT unless there is a clear migration path. (There are lots of interesting details regarding these plans, but that's veering off topic. Feel free to ping me on IRC if you want the gory details.) |
@glaebhoerl Thanks for yet another thorough and well-written RFC! I need to digest the ideas here, but a couple of immediate thoughts:
I need to think more about the proposed traits and macro unification. More feedback later! |
My two cents: I am opposed to changing the name of |
@aturon Thanks for the perceptive comments!
I completely agree with this reasoning in the abstract. I like our short names. I think What seriously bothers me, however, is when name-shortening has the effect of changing the meaning, or at least, of suggesting a different meaning from the one which was intended.
I agree with this also. I think there is merit to both the "data-oriented" nomenclature that Haskell tends to prefer, and which our For the record - while the
I still have the feeling that there should be a better way to do this - this is just the best I've managed to come up with. It could be formulated in terms of
(I'm not going to go through the motions of the so-called "extension trait" dance here.) In the case of |
+1 for renaming To me, |
Option vs Optional has always been the same to me. Colloquially |
The wikipedia article is called Option type, for whatever that's worth. If we rename Option to Maybe to parallel Haskell, let's not create a new convention. Haskell defines their Maybe with Nothing and Just, data Maybe a
= Nothing
| Just a So Rust definition would be: enum Maybe<A> {
Just(A),
Nothing
} |
I disagree with changing from Why? Because both Consider:
compared to:
|
I like They are shorter and more obvious than As for error messages, I might have missed this in the document, but to many of us it is very important not to include debug information such as |
(I'm quite willing to split up the RFC if the core team wants to accept any of the parts separately. But there's no point in doing the work if they're going to be rejected either way.) |
+1 for |
+1 for |
👎 for the names in this RFC. OCaml, Scala, Standard ML, Swift, and Coq all use Alternatively, the functional languages Haskell, Idris, and Agda all use In either case, |
@glaebhoerl I sincerely apologize for the long-overdue attention on this RFC! I'm trying to go through my backlog and found this one. As I think is probably obvious, there's not a strong consensus for the naming change here, which I think would be needed to make such a change at this point. Regarding the changes to the I'm going to close the RFC for the time being. Thanks @glaebhoerl! |
Another proposal inspired by an idea from @aturon. Goes well with #243, but isn't tied to it.
CLICKME