Skip to content
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

Add alternative to Conservative Impl Trait (1522) #2051

Closed
wants to merge 1 commit into from

Conversation

earthengine
Copy link

@earthengine earthengine commented Jun 29, 2017

A new approach to return unboxed closures is proposed.

Rendered

@cramertj cramertj added the T-lang Relevant to the language team, which will review and decide on the RFC. label Jun 29, 2017
@Ixrec
Copy link
Contributor

Ixrec commented Jun 29, 2017

This RFC confuses me greatly. It appears to be unaware of #1951 which is now in FCP, and I can't figure out what this RFC is actually proposing as most of it sounds like a description of what's already been on nightly for a while.

What's the actual change being proposed here?

@TimNN
Copy link
Contributor

TimNN commented Jun 29, 2017

Note that this is an amendment to the existing conservative impl trait RFC (diff) adding a section to the alternatives section.

@Ixrec
Copy link
Contributor

Ixrec commented Jun 29, 2017

@TimNN Ah, thanks, now it makes perfect sense.

@nixpulvis
Copy link

Turns out GitHub isn't a very good forum for RFCs 😢

}
...
let closure = |t|fix(func, t);
```
Copy link
Member

@cramertj cramertj Jun 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't equivalent. In the first function, you're returning a closure which can be evaluated with another argument at a later time. In the second, you're delaying running the function at all until it has been called with the last argument.

Consider, for example, the case where you add a println!("Hello!"); to the beginning of each fix function:

let func = |_| {};

// With `fix` version 1:
let closure = fix(func); // prints "Hello!"
closure(1); // Runs the closure, prints nothing
closure(1); // Runs the closure again, prints nothing

// With `fix` version 2:
let closure = |t| fix(func, t); // prints nothing
closure(1); // prints "Hello!"
closure(1); // prints "Hello!"

@ahicks92
Copy link

I don't fully follow the alternative being proposed here, but nonetheless the point of impl trait is much wider than just closures, and the implementation needed to take it the last inch after we have it should be basically trivial given that closures are already standard types implementing a trait.

Why is this better, unless we're going to throw out the rest of the RFC or something?

@earthengine
Copy link
Author

Let me clarify of this issue. This is not intended to imply any work to be done on the current impl Trait implementation. Instead, the section is added to show a potential workaround, which can be used to simulate the the lacking feature. This is mean to be a historical record, for some research interest.

Some of the comments above is correct, this approach is good for return-by-name, not so good for return-by-value. But in my opinion in many cases this difference is no very important.

@eddyb
Copy link
Member

eddyb commented Jul 3, 2017

@earthengine Try using your technique to return an iterator containing a closure (e.g. .map).

@aturon
Copy link
Member

aturon commented Jul 6, 2017

Thanks much for writing this up, but the lang team is swamped enough with new RFCs that we don't want to spend time hashing out additions to the amendment sections of existing ones. Feel free to open a thread on internals if you think this could lead to a new RFC, though!

@aturon aturon closed this Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants