-
Notifications
You must be signed in to change notification settings - Fork 145
RFC FS-1150—Allow ',' as a separator for pattern matching on named discriminated union fields #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.