-
Notifications
You must be signed in to change notification settings - Fork 22
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
Allow for a shorter deconstruction syntax #781
Comments
If you implement this then the reverse should also work
|
@robkuz that's already what #653 woudl allow, even if the sample are all with an anonymous record instead of a named one and show the feature with property getters instead of simply local variables. But I 100% agree that theses 2 features should work together to provide a simpler unified syntax both in construction and deconstruction position |
I think this would have a wonderful symmetry with #653 |
I'm ok with both this and #653. That said, I'm no particular fan of record pattern matching - I think it makes code obscure. But I can see this improves the situation :) |
Could you clarify whether this this relies on having the names of the record fields identical to the names of the deconstructed values? Assuming this is so, and with typical Pascal casing of record field labels, it feels slightly unaesthetic to end up with a Pascal-cased local value. |
Ideally the default would be same-name deconstruction with an option to specify the name (The already existing |
Yes, it's very unfortunate. Ugh. Discuss. |
Maybe the pascal casing of record field labels convention is not something to be strictly enforced (by whichever mean that would be, like tools like fxcop or gendarme, or naming guidelines), especially if it clashes with some aesthetic aspects of how the record is actually used in the code. From my perspective, for some records it makes sense to have fields pascal case, and others not. For me, (longtime C# user) Pascal case mean public member and exposing fields is discouraged for OO reasons. I don't mind fields (public or not) not being Pascal cased in areas of my code, and in general, I don't mind other aesthetical choices as they inevitably show (unless it is enforced by compiler / language spec) in variety of F# code authored so far. To come back to the shorter deconstruction syntax (I think the consideration on field naming is not the matter of wether the suggestion is useful / desirable), construction and deconstruction of records is pervasive and powerful construct in F# language, and I like how it works with C# anonymous record constructor. |
This would be great for pattern matching and I think it's called field punning in OCaml and Haskell (with a GHC extension) |
We can track this by #653 |
I propose we allow for a deconstruction syntax that would be much shorter to declare especially for anonymous records. The original idea was how to declare React component props in a Fable context with anonymous records but it would also be very nice for standard records in a lot of cases.
I present the deconstruction happening here in parameter position but the same should work in other deconstruction usages.
Existing syntax
Proposal
Proposal for anonymous records
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantages of making this adjustment to F# are ...
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M or L I think but not sure
Related suggestions:
Existing implementations of the concept
Javascript/TypeScript already works the same with a similar syntax (Except with less type inference)
Affidavit
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: