RFC FS-1150 Allow ',' as a separator for pattern matching on named discriminated union fields#818
Conversation
…scriminated union fields
|
EDIT: moved to discussion |
|
This is ready :) |
Co-authored-by: Brian Rourke Boll <[email protected]>
Martin521
left a comment
There was a problem hiding this comment.
It seems line 250 and 301 are inconsistent.
Else this looks very good.
| // | R(a = x, b = y, c = z,) -> ... // trailing comma — OK | ||
| ``` | ||
|
|
||
| Notes: | ||
| - Newlines can separate fields as today. Trailing `,` or `;` after the last field are allowed. |
There was a problem hiding this comment.
This surprises me.
I understand why trailing ; was allowed here: it is also allowed in any other scenario where ; is used as a separator (sequential expressions and anything based on them, record fields, etc.).
To my knowledge, however, there is no existing construct in F# that permits a trailing comma — certainly not union constructors, which this update is ostensibly meant to mirror.
It feels like symmetry with the construction syntax (no trailing commas) should be given more weight here than parity with the ;-based syntax that this is meant to supersede.
Support for trailing commas more generally might be better served by its own, separate suggestion and RFC.
There was a problem hiding this comment.
It feels like symmetry with the construction syntax (no trailing commas) should be given more weight here than parity with the ;-based syntax that this is meant to supersede.
Good point. I agree
There was a problem hiding this comment.
Are you planning further changes to the RFC?
| ```fsharp | ||
| type R = R of a:int * b:int * c:int | ||
|
|
||
| let exNewlines (r: R) = | ||
| match r with | ||
| | R( | ||
| a = x, // newline as separator OK with , | ||
| b = y, | ||
| c = z | ||
| ) -> x + y + z | ||
|
|
||
| let exNewlinesSemicolons (r: R) = | ||
| match r with | ||
| | R( | ||
| a = x; // newline as separator OK with ; | ||
| b = y; | ||
| c = z | ||
| ) -> x + y + z |
There was a problem hiding this comment.
To clarify: newlines without ; were allowed as separators before, including mixed usage —
let exNewlinesSemicolons (r: R) =
match r with
| R(
a = x
b = y; // Semicolon allowed but not required after any of these lines
c = z
) -> x + y + zIs this implying that similar mixed usage would be allowed with commas as well? (I would advise against allowing that, since mixed commas/newlines are not allowed in any other comma-based syntax, including union constructors.)
Click “Files changed” → “⋯” → “View file” for the rendered RFC.