You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
[@gavinking] We could alleviate most of the pain involved in our lack of support for wildcard capture by supplying a couple of functions that accept a wildcarded object or objects, and a generic function, and apply the function to the object or objects. Something like this:
The main reason I'm not proposing to support real wildcard capture is that in full generality the runtime side of it with reified generics looks like it will get pretty hairy. Not impossible, but not easy either.
[@RossTate] It's pretty simple. You do wildcard capture but you ignore implicit constraints (i.e. you only constrain the captured type variable with the explicit given by the in or out annotation). Then you do subtyping as usual with constrained type variables. But if there's an error, then rather than giving types with the ugly capture of stuff, you give their tight approximations. That is, if sub <: super fails, then you report that upper(sub) <: lower (super) failed, where upper(sub) is the most precise supertype that doesn't contain captured variables and lower(super) is the least precise subtype that doesn't contain captured variables. To compute upper and super, you just replace capture variables with their upper or lower bound depending on whether they occur in a co or contravariant position. Except for recursive constraints, upper(sub) <: lower(super) holds/fails if and only if sub <: super holds/fails, so you're not losing any precision. The only corner case is invariant positions, for which you'd need out in use-site annotations to apply this technique.
So you get wildcard capture, but you never have to have capture of in your type errors.
[@gavinking] We could alleviate most of the pain involved in our lack of support for wildcard capture by supplying a couple of functions that accept a wildcarded object or objects, and a generic function, and apply the function to the object or objects. Something like this:
Of course, these functions can't be implemented in Ceylon, they have to be
native
.Also notice that they're pretty painful to use, since you will always need to explicitly specify all the type arguments.
[Migrated from ceylon/ceylon.language#687]
The text was updated successfully, but these errors were encountered: