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

Антон Жилин antonyzhilin at gmail.com
Fri Apr 22 12:17:04 CDT 2016


Vladimir, I agree with Chris Lattner that function parameters are different
from function return value in Swift.

Firstly, syntax of function call allows for easy forwarding of values,
which came from different places, as parameters to a single function:
f(g(foo, 1), h(bar(buz)))

On the other hand, to play with multiple return values as freely, you need
to perform pattern matching, which finishes current expression.

Secondly, there is no special sugar for tuples in return values, and
function grammar does not need to know about it.

Thirdly, there are no special attributes for elements of tuple in function
return type (second implies this).

Now, to  typealias f4 = () -> ((((((()))))))
I think it's OK, but we can remove Void and reduce the number of possible
combinations.

The fact that () and (()) are equal types is a general limitation of Swift
type system: there are no single-element tuples.
But it is so for a reason: parentheses in expressions cannot be overloaded
to construct single-element tuples.

- Anton

2016-04-22 11:12 GMT+03:00 Антон Жилин <antonyzhilin at gmail.com>:

> +1, but this proposal need further work.
> Specification of the new function grammar is needed.
>
> Currently, it looks like:
>
> function-type → type
> <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/type>
> ­throws­opt­->­type
> <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/type>
>
> It is already false, because some attributes can only be used in function
> types.
>
> I suggest to rewrite it to something like:
>
> *function-type* → ( *function-parameter-types*opt ) -> *type*
>
> *function-type* → ( *function-parameter-types*opt ) throws -> *type*
>
> *function-type* → ( *function-parameter-types*opt ) rethrows -> *type*
>
> *function-parameter-types* → *function-parameter-type*
>
> *function-parameter-types* → *function-parameter-type* ,
> *function-parameter-types*
>
> *function-parameter-type* → *function-parameter-attributes* *type*
> It will also eliminate situation when you can pass () argument to a () → T
> function.
> Function types Void->T will need to be migrated.
>
> - Anton
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160422/6e0a1017/attachment.html>


More information about the swift-evolution mailing list