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

First-class generic method / First-class polymorphism / Rank-N types #15810

Closed
be5invis opened this issue Dec 9, 2016 · 4 comments
Closed

First-class generic method / First-class polymorphism / Rank-N types #15810

be5invis opened this issue Dec 9, 2016 · 4 comments

Comments

@be5invis
Copy link

be5invis commented Dec 9, 2016

Given that we have

private void GenericMethod<T, U>(T obj, U parm1)

Which we can use like so:

GenericMethod("test", 1);
GenericMethod(42, "hello world!");
GenericMethod(1.2345, "etc.");

... but it is impossible for now to do this:

public void AnotherMethod(Action<???> method) {
    method("test", 1);
    method(42, "hello world!");
    method(1.2345, "etc.");
}
//...
AnotherMethod(GenericMethod);

...without using reflection/dynamic tricks.

What if we have a forall?

public void AnotherMethod(forall<T, U>. Action<T, U> method) {
    method("test", 1);
    method(42, "hello world!");
    method(1.2345, "etc.");
}
//...
AnotherMethod(GenericMethod);
@orthoxerox
Copy link
Contributor

See also #2212

@alrz
Copy link
Member

alrz commented Dec 10, 2016

You should be passing the containing object so that overload resolution takes place directly on the original method.

class A {   
  public void GenericMethod<T, U>(T obj, U parm1) {}
}

class B {
  public void AnotherMethod(A a) {
    a.GenericMethod("test", 1);
    a.GenericMethod(42, "hello world!");
    a.GenericMethod(1.2345, "etc.");
  } 
}

@be5invis
Copy link
Author

@orthoxerox Higher-kind polymorphism is not higher-rank polymorphism.

@CyrusNajmabadi
Copy link
Member

Closing this out. We're doing all language design now at dotnet/csharplang. If you're still interested in this idea let us know and we can migrate this over to a discussion in that repo. Thanks!

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants