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

Matthew Johnson matthew at anandabits.com
Sat May 28 14:22:00 CDT 2016



Sent from my iPad

> On May 28, 2016, at 12:50 PM, Thorsten Seitz <tseitz42 at icloud.com> wrote:
> 
> 
>> Am 28.05.2016 um 19:35 schrieb Austin Zheng <austinzheng at gmail.com>:
>> 
>> Sorry, 'with' in the second example should be 'where'. My personal preference is to keep 'where' for both uses, since they are serving the same purpose.
>> 
>>>> On May 28, 2016, at 10:33 AM, Austin Zheng <austinzheng at gmail.com> wrote:
>>>> 
>>>> -Thorsten
>>> 
>>> We could make parentheses optional in the general case, and just have them mandatory in the following situations:
>>> 
>>> - You want to nest an existential literal inside another existential literal:
>>> let a : Protocol1, (Protocol2 where .Blah == Int), Protocol3 = foo()
> 
> When using `&` instead of `,` this would not be required (not even for readability IMO).
> 
> 
>>> 
>>> - You want to return an existential with more than one term and/or a where clause from a function that has a generic where clause
>>> func foo<P, Q>(p: P, q: Q) -> (Collection with .Element == P) where P : Equatable { … }
> 
> For return types (if staying with `where` instead of `with`) the parentheses would be required iff only one `where` is present.
> They would not be strictly required if two `where` clauses would be present, but I would be ok if they would be mandatory in that case.
> 
> 
>>> 
>>> - You want to use an existential as a function argument, and that existential has more than one term and/or a where clause
>>> func foo(x: Protocol1, y: (Protocol2 where .Blah == Int), z: Protocol3) { … }
> 
> I wouldn’t require them here. For one the function does not look too bad without the parentheses:
> 
> func foo(x: Protocol1, y: Protocol2 where .Blah == Int, z: Protocol3) { … }
> 
> But even more important: when formatting this function across multiple lines (which I might rather do to improve readability instead of adding parentheses) I would definitely *not* want to have to use parentheses:
> 
> func foo(
> 	x: Protocol1, 
> 	y: Protocol2 where .Blah == Int, 
> 	z: Protocol3) 
> { … }
> 

I agree with everything Thorsten said.  Parents are used to resolve ambiguity.  If we need to go a bit further than is strictly necessary for that purpose in order to make return types feel a bit more consistent that is ok.  I don't mind requiring them for a return type with a where clause, but that's as far as I'd go.

> 
> -Thorsten
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160528/28943046/attachment.html>


More information about the swift-evolution mailing list