-
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
auto-tupling and auto-unit'ing for variable arity fns #258
Conversation
Added client-side flexibility as a motivation for this RFC, along with a quick caveat about generalized auto-tupling at the end.
#257 is both a simpler proposal (from the user's perspective) and would result in code that is easier to read and understand. This RFC suffers from trying to optimize for the ease-of-use of the compiler writer instead of the language user. The first step for API design is to write out the example calls & uses of the API and then to come up with an implementation that would suit that; this RFC did it backwards. |
So the win over current Rust is that you need one less pair of parentheses? The dance of having to define one-off arg traits strikes me as a much larger headache. |
@jfager I assume your critique is directed solely at auto-tupling? (auto-unit'ing gets rid of many Anyway, my thinking wasn't just "ah, this looks nicer without that extra pair of parentheses" -- it is also about forward-migration, where a library can go from version 1 to version 1.1 by replacing a sequence of concrete trailing arguments with one or more traits, and (assuming those traits have appropriate implementations), the client source code will not need to be changed in response (just recompiled). |
@Valloric I'll admit that implementation simplicity is one of my concerns. But I also think there is virtue in exploring how much value one can get out of such a small change. Its entirely possible that #257 will be deemed an acceptable change to the language. Based on my cursory skimming of #257, I am wondering whether both this and #257 are potentially-compatible changes that could both be applied to Rust. Using a trait to express the variable-arity arguments provides the client with more flexibility; but maximizing flexibility is not always the right choice anyway. |
@pnkfelix I'd guess that the large majority of uses would only have one trailing parametric arg intended for overloading, so even for auto-uniting it would generally only be saving one pair of parentheses. When there are multiple trailing parametric args, you could save more sets of parens, true. But working with multiple trailing parametric args seems like it could be dangerous (assuming I'm understanding the rules correctly). Consider a variation on your api evolution example:
|
@jfager Hmm, interesting point. Assuming the person writing the library also defined the But nonetheless, I do agree that there is a risk here, namely when a client has implemented one of the traits for their own types, e.g. So it seems like I overstated the forward-compatibility powers of this proposal: You get one shot at adding some number of trailing parametric args. After that that point, all future extensions must be done through the single final trait. So that makes the auto-unit'ing less useful than I had hoped. |
I appreciate exploring how far we could get without extensive changes to the language, but the root of the problem remains that no user, when asked to provide an example of how they would like to use optional/keyword args, would come up with "I want a to write a trait for every function for which I want to have keyword args and then I want to impl that trait in various ways and write many lines of code to get something I can do with a few chars in any other modern language." And that's not a straw-man, this proposal does require writing way more code to get optional/keyword args than other languages. I understand that this approach is simple to implement in the compiler, but there's a handful of rustc developers and thousands of Rust users (and there's every intent that the number of users grows to millions). I'm sorry, but you're optimizing for the wrong thing.
That is probably a bad idea. There should be one and only one obvious way to do it. |
closing as postponed, filing with RFC issue #323 |
Summary
Add support for default and variable-arity functions via a small language feature and a simple programming pattern. The language feature is solely a pair of changes to the treatment of function call-sites:
()
. I call this "auto-unit'ing."The above two transformations can be used in tandem with the trait system as a way to express optional parameters and multiple-arity functions.
(rendered)