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

David Owens II david at owensd.io
Tue Apr 19 11:16:23 CDT 2016


> On Apr 19, 2016, at 7: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 <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>> on Fri Apr 15 2016, Brent Royal-Gordon <swift-evolution at swift.org <mailto: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.

For the sake of consistency, would you also support the requirement of `-> Void` on functions that return nothing? There are a few different ways to declare function signatures, one of which requires the return type, the other can default one for, in the "degenerate case".

Example:

typealias Callback = () -> Void     // return type required
let f: () -> Void = {}              // return type required

func g() {}                         // return type optional
func h() -> Void {}                 // should this be required?

I think it's clear from this example, that consistency is not always the most important thing.

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


More information about the swift-evolution mailing list