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

Proposal: Static Generics #3460

Closed
hez2010 opened this issue May 15, 2020 · 6 comments
Closed

Proposal: Static Generics #3460

hez2010 opened this issue May 15, 2020 · 6 comments

Comments

@hez2010
Copy link

hez2010 commented May 15, 2020

Proposal: Static Generics

For people who are not familiar with Static Generics, please see https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters

Proposed syntax

Use inline to mark the functions/classes are resolved from caller,'T for static generic type parameters.

inline void 'T Foo<'T>('T x, 'T y)
{
    return x + y; // requires static member '+'
}

void Main()
{
    var x = Foo(5, 6); // 11
    var y = Foo("Hel", "lo"); // "Hello"
    var z = Foo(new { }, 234); // error
}
@Richiban
Copy link

This functionality will hopefully be provided by the shapes proposal. #164

@huoyaoyuan
Copy link
Member

An enhancement of generic type system should have been planned for C# 10 (See Language Version Planning). We don't need to open new issues for specific scenarios, as the enhancement are supposed to be wider.

The language team is currently completing C# 9 that features records. Once C# 9 has been completed, they should be able to focus on the enhancement.

@333fred
Copy link
Member

333fred commented May 16, 2020

There is some type system improvement stuff triaged into 10, but I wouldn't expect anything really big until 11. Some of the stuff in 10 is there to make sure we talk about it during that time frame.

@Lemmingh
Copy link

Lemmingh commented Sep 5, 2020

Generic method has already made code analysis awkward sometimes, for example, locking.

I'm afraid the current proposal would introduce more hard-to-lint cases.

IMHO, restrictions should be added at least. What about:

  • must not exceed internal.
  • must specify type parameter constraints.

@YairHalberstadt
Copy link
Contributor

Closing as being looked at as part of #164, #1711

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

7 participants
@Richiban @333fred @huoyaoyuan @hez2010 @YairHalberstadt @Lemmingh and others