Open baronfel opened 6 months ago
It's interesting how these two examples are currently represented differently in the AST—compare the SynBinding
's headPat
, returnInfo
, and expr
:
let (x : int) = 3
let x : int = 3
Separately, there are also several expression contexts where an unparenthesized type annotation is currently disallowed that I came across in https://github.com/dotnet/fsharp/pull/16079:
I have neither looked into the compiler nor reasoned from first principles as to why that might be for each case, but if somebody looks at addressing this issue, it may be worth looking into those as well.
At least for some other pattern contexts there are good reasons why parentheses are and must be required, since, e.g., a trailing ->
, |
, or &
token could otherwise be interpreted as part of the type:
fun (x : …) -> …
function (x : …) -> …
match … with (x : …) -> …
(x : int) | x
(x : int) & y
I propose we
allow CE let-bindings to accept typed patterns without required parenthesis:
The existing way of approaching this problem in F# is
to wrap the type pattern in parenthesis:
Pros and Cons
The advantages of making this adjustment to F# are
it removes a syntactical foot-gun that is frustrating and confusing to users.
The disadvantages of making this adjustment to F# are
it is a slight special casing of the allowable patterns in CE bindings and so may make the parser/lexer/checker more complicated
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S to M
Related suggestions:
Affidavit (please submit!)
Please tick these items by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.