Skip to content

WIP: with- keyword support for anonymous records #11911

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

Closed
wants to merge 2 commits into from

Conversation

vzarytovskii
Copy link
Member

@vzarytovskii vzarytovskii commented Aug 4, 2021

This is pretty much a WIP or an experiment of adding a without (or with-) keyword support for anonymous records.

Note: things may change (e.g. keyword itself (as many people don't like with-), implementation details, language switch, etc).

RFC: https://github.com/fsharp/fslang-design/blob/main/RFCs/FS-1072-without-anonymous-records.md

Discussion: fsharp/fslang-design#616

Things to be done:

  • Lexer/parser with- support for anonymous records expression.
  • Actual logic to remove fields when creating new AnonRecd.
  • Tests

@vzarytovskii vzarytovskii marked this pull request as draft August 4, 2021 14:03
@vzarytovskii vzarytovskii changed the title WIP: 'with-' keyword support for anonymous records WIP: with- keyword support for anonymous records Aug 4, 2021
@vzarytovskii vzarytovskii self-assigned this Aug 4, 2021
@@ -477,8 +477,9 @@ type SynExpr =

| AnonRecd of
isStruct: bool *
copyInfo:(SynExpr * BlockSeparator) option *
recordFields:(Ident * SynExpr) list *
copyInfo: (SynExpr * BlockSeparator) option *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have the range of the with- keyword in the tree as well?
This would be useful for Fantomas if the code has a comment after the with- for example.

type A = { X: int; Y: int }
let a = { X = 1; Y = 2 }
let b = {| a with- // foo 
                                  Y |}

Fsx """
type A = { X: int }
let a = { X = 1 }
let b = {| a with- X |}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be quite a use case for #6941

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a with- to always remove the field. When the fields already present are controlled elsewhere, I would want this to be a guarantee.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow of fields should allow an empty state where more fields can be added later.

@KevinRansom
Copy link
Contributor

Closing, two years without attention, please reopen if you want to work on completiong this.

Thanks

Kevin

@vzarytovskii
Copy link
Member Author

Gonna close it for now, needs more thinking in regards of spread operator

@vzarytovskii vzarytovskii deleted the without-anonrecd branch May 22, 2023 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants