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(stringpath){/*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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.