[swift-evolution] [Returned for Revision] SE-0095: Replace protocol<P1, P2> syntax with Any<P1, P2>
Austin Zheng
austinzheng at gmail.com
Thu Jun 2 01:48:05 CDT 2016
I definitely agree with your concern about angle brackets being used outside a generic context. However, I think I'd prefer the core team syntax (unadorned "P1 & P2") if delimiters are out of the question for now.
One option might be to use parentheses: Any(X & Y & Z), or square brackets: Any[X & Y & Z]. The former might look too much like a function call, although if we're going to call '&' a type infix operator we might as well stretch the analogy as far as it'll go. I actually like the second approach: you can't define static subscripts (and you wouldn't be able to define them on `Any` even if you could), so it wouldn't occupy an already-extant syntactic slot. Either would give existential types their own characteristic syntax, avoiding the angle brackets issue you brought up.
Austin
> On Jun 1, 2016, at 11:39 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> On Thu, Jun 2, 2016 at 12:42 AM, Austin Zheng via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Excellent.
>
> I put together a PR with a revised proposal containing the core team's recommended approach. If anyone is curious they can see it here: https://github.com/austinzheng/swift-evolution/blob/ef6adbe0fe09bff6c44c6aa9d73ee407629235ce/proposals/0095-any-as-existential.md <https://github.com/austinzheng/swift-evolution/blob/ef6adbe0fe09bff6c44c6aa9d73ee407629235ce/proposals/0095-any-as-existential.md>
>
> Since this is the de-facto second round discussion thread, I'll start with my personal opinion (which is *not* reflected in the PR): the '&' separators in lieu of commas are a good idea, but I would still prefer the types to be wrapped in "Any<>", at least when being used as existentials.
>
> My reasons:
>
> - Jordan Rose brought up a good point in one of the discussion threads today: a resilience goal is to allow a library to add an associated type to a protocol that had none and not have it break user code. If this is true whatever syntax is used for existentials in Swift 3 should be a valid subset of the generalized existential syntax used to describe protocol compositions with no associated types.
>
> - I would rather have "Any<>" be used consistently across all existential types eventually than have it only be used for (e.g.) existential types with `where` constraints, or allowing two different representations of the same existential type (one with Any, and one without).
>
> - I think any generalized existential syntax without delimiting markers (like angle braces) is harder to read than syntax with such markers, so I would prefer a design with those markers.
>
> Agree with your reasons, but I'm still uncomfortable that things inside the angle brackets would behave differently here than elsewhere. Would it help to make a keyword out of `any` for existentials? Then you could have this:
>
> ```
> func foo(value: any X & Y)
> ```
>
> Best,
> Austin
>
>> On Jun 1, 2016, at 10:17 PM, Chris Lattner <clattner at apple.com <mailto:clattner at apple.com>> wrote:
>>
>>
>>> On Jun 1, 2016, at 9:53 PM, Austin Zheng <austinzheng at gmail.com <mailto:austinzheng at gmail.com>> wrote:
>>>
>>> This was indeed a very thorough review by the core team. I'll prepare a v2 proposal with this feedback taken into account so we can continue moving things along.
>>>
>>> One quick question - is making whatever syntax is chosen for Swift 3 "forward-compatible" with a future generalized existential feature a concern?
>>
>> Yes it is a concern, but we assume that the “X & Y” syntax will always be accepted going forward, as sugar for the more general feature that is yet to be designed.
>>
>> -Chris
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160601/c34c9e5c/attachment.html>
More information about the swift-evolution
mailing list