[swift-evolution] [pitch] Eliminate the "T1 -> T2" syntax, require "(T1) -> T2"

David Rönnqvist david.ronnqvist at gmail.com
Tue Apr 19 10:44:16 CDT 2016

Would this also affect the syntax for naming closure arguments? For example, would this (taken from "The Swift Programming Language (Swift 2.2)”):
  reversed = names.sort( { s1, s2 in return s1 > s2 } )
have to be written like this:
  reversed = names.sort( { (s1, s2) in return s1 > s2 } )
or is that a different syntax?

As a developer focused on _writing_ and _reading_ code like this, I don’t see the real benefits of this change. It only feels natural to me that I would be able to omit the parentheses when there is only one type, but that I would need them to group multiple arguments or to label arguments.

That said, I don’t feel strongly about it and the work of transitioning our code would be minimal. If this change provides other engineering benefits that aren’t noticeable on the surface, then I’m positive to the change for those reasons.

- David
> On 19 Apr 2016, at 16:59, Sean Heber via swift-evolution <swift-evolution at swift.org> wrote:
> For what it’s worth, I searched my Swift code and didn’t find a single instance where I did *not* use the parens - even for single-argument functions. Until this conversation came up, I don’t recall if it ever even occurred to me that I *could* leave the parentheses out!
> l8r
> Sean
>> On Apr 19, 2016, at 9:49 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
>>> On Apr 18, 2016, at 4:31 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>>> on Fri Apr 15 2016, Brent Royal-Gordon <swift-evolution at swift.org> wrote:
>>>>> Given all this, I think it makes sense to go for syntactic
>>>>> uniformity between parameter list and function types, and just
>>>>> require parenthesis on the argument list.  The types above can be
>>>>> trivially written as:
>>>>> (Int) -> Float
>>>>> (String) -> ()
>>>>> Thoughts?
>>>> While it's technically correct, I agree with John's assessment that
>>>> this is "fussy". `T -> U` doesn't confuse people 
>>> Do we have any data on this (in either direction)?
>>> Personally, it has always seemed obvious that T -> U being a function
>>> type would be quite novel to some people, considering the number of
>>> times I've seen in Haskell texts that (surprise!) you don't need
>>> parentheses to invoke functions.  I guess those are invocations and
>>> we're talking about declarations here, but declaration-follows-use is a
>>> kind of principle the language tries to uphold.
>>> But that's just intuition.  Data would be very interesting.
>> Apart from intuition and confusion, parentheses are used at call sites
>> and declarations. It seems out of line that they can be removed in types 
>> but only in one degenerate case.
>> This goes against the Swift core design goal of consistency.
>> -- E
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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

More information about the swift-evolution mailing list