A high precedence application expression is one in which an identifier is immediately following by a left paren without intervening whitespace, e.g., f(g)
. Parentheses are required when passing these as function arguments: func (f(g))
.
Section 15.2 of the spec states the grammar and precedence rules allow the unparenthesized form -- func f(g)
-- but an additional check prevents this.
Why is this intentionally prohibited? It would obviate the need for excessive parentheses and piping, and generally make the code much cle开发者_开发技巧aner.
A common example is
raise <| IndexOutOfRangeException()
or
raise (IndexOutOfRangeException())
could become simply
raise IndexOutOfRangeException()
I agree that the need for writing the additional parentheses is a bit annoying. I think that the main reason why it is not allowed to omit them is that adding a whitespace would then change the meaning of your code in quite a significant way:
// Call 'foo' with the result of 'bar()' as an argument
foo bar()
// Call 'foo' with 'bar' as the first argument and '()' as the second
foo bar ()
There are still some rough edges where adding parens changes the evaluation (see this form post), but that "just" changes the evaluation order. This would change the meaning of your code!
精彩评论