[swift-evolution] Enhanced existential types proposal discussion

Adrian Zubarev adrian.zubarev at devandartist.com
Fri May 20 08:52:21 CDT 2016


Actually I’ve done my homework and I can tell you that it will be possible if SE-0095 is accepted.

Here is how to abuse this:

protocol A {}
protocol B {}

typealias AB = protocol<A, B>

protocol C: AB {}

That renamed will be:

protocol A {}
protocol B {}

typealias AB = Any<A, B>

protocol C: AB {}

Do we need this or should we ban this?

I’m not sure, because we can’t use `Any<…>` directly on a protocol. Using a typealias was a workaround that worked.

If we keep it that way, it will be fine with my proposal of disallowing redundant types `Any<…>` could create: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160516/018280.html

It looks strange if you can only use typealias for that. If we change that so we could use `Any<…>` directly one would ask why can’t we use `Any<UIView>` on protocols? This is a different story, because we never talked if we can build protocols with type requirement.

-- 
Adrian Zubarev
Sent with Airmail

Am 20. Mai 2016 bei 15:02:35, Adrian Zubarev (adrian.zubarev at devandartist.com) schrieb:

Can we use `Any<…>` for protocol conformance like this: 

protocol A: Any<class> {} <— this makes a little sense, but I’d rather write protocol A: class {} instead

protocol B: Any<UIView, SomeProtocol>  <— this is confusing. One could argue we could apply B only on any UIView subclass which conforms to SomeProtocol, but why can’t we do also this: protocol C: Any<UIView> 

One downside here is that `Any<UIView> == UIView` and should be banned because its redundant.

We cannot write something like this:

protocol C: UIView 

Or can we?

I’d propose we should ban this in Swift 3. 
This implies that `typealias AnyObject = Any<class>` won’t work anymore on protocols. This is a breaking change. 
I’d write a small proposal as another follow up to SE-0095 if my thoughts are right.

-- 
Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160520/ffccad56/attachment.html>


More information about the swift-evolution mailing list