-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Function Generics Seems Redundant #2842
Comments
What part of it seems redundant? |
@catamorphism The markdown was obscuring his argument, take a look once more. :) |
The function name. Sorry. |
It's true that it would be pretty simple to infer the bindings for type parameters in this case. But if you wrote a function with bounded type parameters (that is, "T must have trait foo"), it wouldn't be as straightforward (the typechecker would need to look at the whole function body, not just the signature). To keep type inference simple, we don't want to have to scrutinize the entire body to know the bounds for the type parameters. That is, if your function was:
then the type signature by itself doesn't give you enough information to infer that For consistency, we require type parameter bindings for all type parameters, not just bounded ones. |
In Rust, the rule is that ∀ is always explicit. In type-theoretic notation, the type of
Consider that if the ∀ were in a different location, it wouldn't typecheck. The type above is distinct from this type:
So I think Rust's rules help clarity. And, as Tim mentioned, we need a place to put trait bounds. |
Rustup Also add a test for rust-lang#110233
Given this function signature:
fn bimap<K, V> (map: hashmap<K, V>) -> bimap<K, V>
The addition of
<K, V>
on the function name (bimap) seems redundant, and is an element of surprise to new users of the language (if I count as a new user.)The text was updated successfully, but these errors were encountered: