Allow Existential types #4597
Replies: 1 comment
-
Duplicate of #1328. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Existential types, or 'existentials' for short, are a way of 'squashing' a group of types into one, single type.
Problem
For example, the LINQ Count method defines a
T
, but it really does not care about it; It does nothing with theT
instance.This is bad, because it limit us unnecessarily. For example, if we have some object and case it is a generic enumerable, we want to count how many elements it has. This can not be simple done, because we need to supply
T
to callCount
method, even when we does not care.I see 2 drawbacks here:
IEnumerable
) to grup this values loosing the information that is a generic enumerableT
and then be able to callCount
Solution
Discard T, where we does not care about it..
Then
All runtime information is still there, and
Count
method as wellvalues
variable are still generic, the compiler just let us discard it since it is not relevant for the current context. Of course, we still could callCount
with anIEnumerable<T>
likestring[]
, we are just not restrict to it.An alternative approach, much simple, is allow something like following
Beta Was this translation helpful? Give feedback.
All reactions