Emulating first-class polymorphism
Last time, we talked about universally quantified types and the challenge of passing a generic functi...
For further actions, you may consider blocking this person and/or reporting abuse
What syntax would you recommend if it were supported? I can't expect you think users should type nonstandard characters in regular use. Is there a keyword that might make more sense?
This is a good question. We could introduce a keyword like
exists
for existential quantification, but I don't it would actually be necessary. Imagine if we could declare a function like this:Note that I've removed the
<T>
declaration after the name ofDeserializeList
, but the function still returns anIList<T>
. This would currently generate a compiler error, but we could instead safely (I think) interpret the returnedIList<T>
to be existentially quantified. Basically, this would mean "I give you back anIList<T>
, but you can't know whatT
actually is at compile-time."Someone who knows more about the C# compiler and type theory could probably give a better answer than me, though. In practice, existential types can be converted to universal types with some effort (as we'll see in the next post), so we do have a workaround for now.