[swift-evolution] [Pitch] Require Any for existentials

Karl razielim at gmail.com
Wed Aug 24 09:32:27 CDT 2016


> On 24 Aug 2016, at 00:14, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
> 
> The basic design is fine, but I wouldn't want to add more noise to my code. We could keep (label: Protocol) as a shorthand form for (label: Any<Protocol>) similar to Optionals.
> 
> What's the benifite of this anywasys? What exactly will this solve?! 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail

The problem, as I understand it, is that when you use “MyProtocol” as a type, there is sometimes a confusion as to whether you mean:
- the protocol itself, or
- anything which “is” that protocol (similar to how I might write “MyClass” when meaning anything which “is” a MyClass, including MyDerviedClass), i.e. an existential

See the discussion about protocol self-conformance. Any<MyProtocol> would make it clear that you mean the latter.

I quite like using protocol names to refer to existentials. I’d like to consider the other options for disambiguating the protocol type before giving a +/- 1. This would fit nicely with another commonly-requested feature though: the ability to constrain concrete types by protocol conformance - e.g. UIView<MyProtocol>.

Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160824/985e9590/attachment.html>


More information about the swift-evolution mailing list