-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Proposal: Default Generic Type Parameter #6248
Comments
@alrz Lucky for us you're not aware of the work to add higher kinded types oops 🙊 |
@alrz how will you disambiguate between creating instances of classes |
@orthoxerox |
That's it? Well that was not helpful either. |
Foo<> already have a meaning inside typeof(), which obviously can't change. |
@gafter Any further details forthcoming on this work? I do think this is a useful idea. It would allow users to use generic methods/types without necessarily having to specify each type if they're happy with the default, thus potentially making consumption far more straightforward. TypeScript has a similar proposal currently. |
@MgSam Any further details on what work? Higher-kinded types? If anything it is years away, and would be led by changes to F# and CLR. |
I think this can eliminate the need for generic/non generic variations of types without breaking existing code, interface IEnumerator<T = object> {
T Current { get; }
bool MoveNext();
...
}
interface IEnumerable<T = object> : IEnumerable {
IEnumerator<T> GetEnumerator();
} |
I'm not sure what that means. Are you saying that there would be type equivalence between interface IEnumerator<T = object> {
T Current;
bool MoveNext();
} and interface IEnumerator {
object Current;
bool MoveNext();
} ? new ArrayList() is IEnumerable == true and new ArrayList() is IEnumerable<object> == false and typeof(IEnumerator<>) != typeof(IEnumerator) |
@aluanhaddad I'm saying that we could get rid of non-generic |
Moved to dotnet/csharplang#278 |
The ability to specify a default type for a generic type parameter:
As a real world example, the
IdentityDbContext
class in ASP.NET Identity:to avoid the need to declare different subtypes for different default types like
In companion with improved type aliases can avoid this for god's sake.
To use default type parameters, one may skip the type parameter as follow:
This has some interactions with generic type argument inference proposals like #5429 or #2319.
The text was updated successfully, but these errors were encountered: