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

Implied field names for anonymous records #734

Closed
5 tasks done
SchlenkR opened this issue Apr 9, 2019 · 2 comments
Closed
5 tasks done

Implied field names for anonymous records #734

SchlenkR opened this issue Apr 9, 2019 · 2 comments

Comments

@SchlenkR
Copy link

SchlenkR commented Apr 9, 2019

Implied field names for anonymous records

I propose we implement a feature that extends the way in which field names of anonymous records are expressed. Currently, the field names have to be written explicitly, followed by the value assignement. Instead, field names could be implied by the name of the value assignement expression.

Example:

type Foo = { id: int; name: string }
let foo = { id=42; name="Hans" }
let bar = 4711

// I suggest we write
let fooBar = {| foo.name; bar; |}

(* instead of
let fooBar = {| name=foo.name; bar=bar |}
*)

Implied names should work at least for:

  • Record fields
  • Class / struct fields and properties
  • identifiers (let; dynamic operator)
  • evaluated functions (propably too implicit; better explicit naming?)

C# has a similar feature.

Pros and Cons

The advantages of making this adjustment to F# is the removal of redundant information that has to be typed in by the user. Especially when working with types that have a lot of properties, this feature can improve the anonymous records experience.

When working interactively with FSI, shortcuts and ease of use are important for an uninterrupted workflow. Quick transformations of data is a key point, and "subtracting" properties from large types is an often performed use case:

query {
    for x in context.Shipments do
    // do some stuff...
    select {| x.id; x.name; x.shipmentCode.whatever |}
}
|> printAsTable

The disadvantages of making this adjustment to F# are more shortcuts a

Extra information

{| foo.name; bar; |} should equal {| name = foo.name; bar = bar; |} .

Estimated cost (XS, S, M, L, XL, XXL): I've never worked in FSC project, but I guess compared to other features maybe S?

Related suggestions: #207

Affidavit (please submit!)

Please tick this 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
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • 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.

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
@SchlenkR
Copy link
Author

SchlenkR commented Apr 9, 2019

Duplicate of #653

@charlesroddie
Copy link

charlesroddie commented Apr 11, 2019

Duplicate of #653

@ronaldschlenker you can close this issue.

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

2 participants