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

Michael Peternell michael.peternell at gmx.at
Tue Apr 19 13:30:51 CDT 2016


@Radek:
I totally agree, and would like to add some more reasons.

(For me), (parenthesis are mostly (a tool) to disambiguate the (parse tree)). a parenthesis around (just (one token)) doesn't really make sense, or disambiguate anything, IMHO. They tell the parser, "you think I meant 'a+(b^2)' but I really meant '(a+b)^2', so I have put parens around 'a+b'". I don't need to write "a+(b^2)" (given that "^" means exponentiation.) To use them for function application is okay though, because I have been used to it for a very long time, and because they serve a different role there, I guess.

For example 2 + (3 * 4) is different than (2 + 3) * 4. The first one is the default, because "*" binds stronger; if you want the second version you need the parens. On the other hand, ((2) + ((3) * (4))) doesn't really make anything more consistent than just writing 2 + 3*4. It looks more like a properly expanded C macro.

At least from a mathematical point of view, (and as a future language user), I feel that "Int -> Int" looks much more intuitive than "(Int) -> Int".

And for all those guys who feel that "(Int) -> Int" is more "consistent": No one will prevent you from writing "(Int) -> Int". It's already valid Swift, right?

Just my 2 cents.

-Michael



More information about the swift-evolution mailing list