[swift-evolution] Enhanced existential types proposal discussion
Brent Royal-Gordon
brent at architechies.com
Fri May 27 04:54:31 CDT 2016
> // With the new collection model (SE-0065), indices are simply Comparable now
> // Okay to cast from x.Index to Comparable
> let a = anIndex as Comparable
>
> // Not okay to cast from Comparable to y.Index
> let b = a as y.Index
>
> // This should be okay. We may want to break this feature into 'Opening Existentials' follow-up proposal
> if let b = a as? y.Index {
> // do stuff with b
> }
If you're going to do this, it might make sense to add a new form of `as?`/`as!` cast for casting between the same associated type on different existentials:
if let b = x.startIndex as? y.Index {
// do stuff with b
}
This would succeed if the concrete types of `x` and `y` had the same type for `Index`, and fail otherwise.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list