[swift-evolution] [swift-evolution-announce] [Review] SE-0089: Replace protocol<P1, P2> syntax with Any<P1, P2>
Thorsten Seitz
tseitz42 at icloud.com
Sat May 28 12:50:04 CDT 2016
> 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 <mailto: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)
{ … }
-Thorsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160528/de32add3/attachment.html>
More information about the swift-evolution
mailing list