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

Remove type parameter default on functions and methods #32

Closed
bluss opened this issue Jan 13, 2016 · 6 comments
Closed

Remove type parameter default on functions and methods #32

bluss opened this issue Jan 13, 2016 · 6 comments

Comments

@bluss
Copy link

bluss commented Jan 13, 2016

See rust-lang/rust#30724 and https://gist.github.com/nikomatsakis/760c6a67698bd24253bf

These are warnings in the nightly.

@m4rw3r m4rw3r closed this as completed in 749d992 Jan 13, 2016
@bluss
Copy link
Author

bluss commented Jan 13, 2016

I don't know exactly where these discussions were, but the language team wants to basically back out of the type parameter defaults feature for functions altogether. It makes sense to remove these while they are still duds.

@bluss
Copy link
Author

bluss commented Jan 13, 2016

This was of course contrary to my hope and the library API evolution use case I wanted to have available.

@m4rw3r
Copy link
Owner

m4rw3r commented Jan 13, 2016

I can see why they want to remove it, it is an extra feature which might not be needed. Maybe the working related to HKTs could shed some light on what is needed (I assume that some type-defaults would be really neat to have there). But I am still a bit surprised that types and traits are treated differently compared to functions.

@bluss
Copy link
Author

bluss commented Jan 13, 2016

if functions were treated like struct and trait then:

fn id<T=u32>(t: T) -> T { t }

id(2); // calls id::<u32>()
id("hi"); // tries to call id::<u32>() and produces an error
id::<&str>("hi"); // ok

which is very limited!

@m4rw3r
Copy link
Owner

m4rw3r commented Jan 13, 2016

Wouldn't the above example with id("hi") still infer to id::<&str>("hi")? From the small tests on play.rust-lang.org it seems like struct Id<T=u32>(T) behaves identically to fn id<T=u32>(t: T) -> T { t } with the excption of the wrapper itself.

@bluss
Copy link
Author

bluss commented Jan 13, 2016

True, the Id(xyz) constructor will be generic that way. I was thinking of the way you name the type, so for example in fn default() -> Id and let x: Id, the default is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants