[swift-evolution] [Manifesto] Completing Generics
jgroff at apple.com
Wed Mar 2 20:06:10 CST 2016
> On Mar 2, 2016, at 5:50 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> If protocols are namespaced separately from types, you could still do something like:
> typealias Drawable: Drawable = Any<Drawable>
> if you intend to use the protocol type primarily as a dynamic type (and assert that it's self-conforming).
…and along similar lines, you might also want to extend an existential type to conform to itself (or other protocols) when it doesn't naturally do so by type erasure. For instance, the `Any*Collection` want to type-erase their contained collection's associated Index type; this is statically unsound since the Index requirement in Collection is contravariant, but is allowed by the dynamic semantics of Index, which require as a precondition that indexes only be applied to their originating collection. There's also our oft-lamented inability to have heterogeneous Sets of protocol type; if you could extend an existential to conform to Hashable, instead of forcing the protocol to refine Hashable, that would give you the ability to use it with Set in the obvious way.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution