Skip to content

re: Existentially quantified types in C# VIEW POST

re: 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 ...

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:

IList<T> DeserializeList(string path) { /*impl*/ }

Note that I've removed the <T> declaration after the name of DeserializeList, but the function still returns an IList<T>. This would currently generate a compiler error, but we could instead safely (I think) interpret the returned IList<T> to be existentially quantified. Basically, this would mean "I give you back an IList<T>, but you can't know what T 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.

code of conduct - report abuse