[swift-evolution] [swift-evolution-announce] [Review] SE-0089: Replace protocol<P1, P2> syntax with Any<P1, P2>

Kevin Ballard kevin at sb.org
Tue May 24 21:55:06 CDT 2016


On Tue, May 24, 2016, at 11:06 AM, Chris Lattner wrote:
> 	* What is your evaluation of the proposal?

+1. protocol<...> feels like a weird corner of the language that not a lot of people know about. Also, changing to Any<...> opens the door to allowing classes in the list instead of just protocols (protocol<UIViewController, MyProto> doesn't make much sense, but Any<UIViewController, MyProto> is fine).

I prefer to spell it as Any instead of any. I think the biggest reason is because Any, without brackets, is used as an existential type, and it would be weird to have a lowercase identifier used as a type. Arguably we could introduce any<...> and make Any just a typealias for any<>, but that seems potentially confusing, so I'd rather just have Any and Any<...>.

Joe Groff's infix notation proposal has some merit, and I'd like to mention one other point in favor: Any<P,Q> and Any<Q,P> are equivalent types, but it's not immediately obvious that they should be, since all other uses of type parameters care about type ordering. Infix notation gets rid of the assumption of ordering (since infix operators like + are usually commutative). But it is a more dramatic change, and we can always consider switching to that later if we want (I imagine that usage of protocol<...> is fairly rare so not many people will be impacted by this change), and it does have the drawbacks that Joe mentioned which are non-trivial.

> 	* Is the problem being addressed significant enough to warrant a change to Swift?

Probably, yeah. It removes a rarely-used construct in favor of one that people are probably more familiar with, and as I mentioned before it opens the door to allowing Any<SomeClass,SomeProto> (which is an Obj-C feature that Swift currently has no equivalent for).

> 	* Does this proposal fit well with the feel and direction of Swift?

Yes.

> 	* If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

The only language that comes to mind where I'm familiar with the equivalent functionality is Rust, and as Joe Groff already said, Rust uses an infix operator for this.

> 	* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

A quick reading of the proposal and reading the review thread to date.

-Kevin Ballard


More information about the swift-evolution mailing list