Skip to content
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

Infer latest matching record type for copy-and-update expressions #1330

Open
5 of 6 tasks
cmeeren opened this issue Oct 27, 2023 · 0 comments
Open
5 of 6 tasks

Infer latest matching record type for copy-and-update expressions #1330

cmeeren opened this issue Oct 27, 2023 · 0 comments

Comments

@cmeeren
Copy link

cmeeren commented Oct 27, 2023

I'd like to see better type inference for record copy-and-update expressions. When there are multiple matching record types in scope, it should default to the latest one, just like when using ..

type Record1 = { X: int; Y: string }
type Record2 = { X: int }

// Successfully infers Record2
let getX a = a.X 

// Fails with FS0667: Labels do not uniquely determine a corresponding record type.
// Ideally it should infer Record2.
let setX value a = { a with X = value }

The existing way of approaching this problem in F# is using type annotations.

Pros and Cons

The advantages of making this adjustment to F# are: Improved usability and consistency.

The disadvantages of making this adjustment to F# are: Less explicit types (though again, it's consistent with . capabilities).

Extra information

Estimated cost (XS, S, M, L, XL, XXL): M

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick these items by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on StackOverflow) and I have searched StackOverflow for discussions of this issue
  • This is a language change and not purely a tooling change (e.g. compiler bug, editor support, warning/error messages, new warning, non-breaking optimisation) belonging to the compiler and tooling repository
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant