First class polymorphism / Rank-N types #549
Replies: 8 comments
-
What are you trying to express with the upside-down A? I've read your post 3 times and I still don't understand whatever it is that you're trying to suggest. |
Beta Was this translation helpful? Give feedback.
-
@yaakov-h Precisely it is "Rank-N Type". |
Beta Was this translation helpful? Give feedback.
-
So you want an open generic delegate rather than a closed generic delegate? If I understand correctly, the problem with that is type safety can't be checked at compile time and must be checked at runtime. That puts it firmly in the dynamic/reflection world. Different note, if we get union types and you can take an |
Beta Was this translation helpful? Give feedback.
-
@jnm2 For typechecking, @simonpj (Simon Peyton Jones FRS) has a paper about this: |
Beta Was this translation helpful? Give feedback.
-
What is an example use case that this is trying to solve? Why is variance if the |
Beta Was this translation helpful? Give feedback.
-
@HaloFour In SPJ's paper there are multiple examples of RNT. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I think to do this properly, it would require pretty significant changes to the CLR and, even worse, to the metadata format. The last time that happened, it was in .Net 2.0 for generics. So this would have incredibly high costs. And it's not hard to work around this limitation by using a custom abstract class instead of open delegate type. Something like (assuming public abstract class GenericAction2
{
public abstract void Invoke<T1, T2>(T1 arg1, T2 arg2);
}
sealed class MyGenericAction : GenericAction2
{
public override void Invoke<T, U>(T obj, U parm1) => GenericMethod(obj, parm1);
}
public void AnotherMethod(GenericAction2 method) {
method.Invoke("test", 1);
method.Invoke(42, "hello world!");
method.Invoke(1.2345, "etc.");
} The syntax is not as nice as what you're proposing, but it's not that bad. So this feature has:
Because of that, I don't see this happening. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Given that we have
Which we can use like so:
... but it is impossible for now to do this:
...without using reflection/dynamic tricks.
What if we have a
∀
?Beta Was this translation helpful? Give feedback.
All reactions