You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose we produce deconstructors automatically for F# records.
The new C# 7 language enhancements allow you to produce custom deconstructors to coincide with the introduction of the ValueTuple<T> type and tuple support in the language.
It seems that it would make sense for F# records to provide a predefined deconstructor for F records either by default or via an attribute like [<ProvidesDeconstructor>].
The existing way of approaching this problem in F# is to roll your own deconstructor via a type extension, but records and deconstructors seem to go hand in hand.
Pros and Cons
The advantages of making this adjustment to F# are that:
We would have better interop with C# 7 out the box
We would reduce the introduction of possible boilerplate code
The disadvantages of making this adjustment to F# are:
This is yet another example of pre-generated code which some people may not appreciate or may consider yet another concept to learn.
Extra information
C# currently does not allow deconstructors for single return values, so a record of 1 item would either need to not provide deconstructor or produce a warning or error.
Estimated cost (XS, S, M, L, XL, XXL):
S
Related suggestions: (put links to reated suggestions here)
Affadavit (must be submitted)
Please tick this by placing a cross in the box:
[ x] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
[ x] 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:
[ x] This is not a breaking change to the F# language design
[ x] I would be willing to help implement and/or test this
I or my company would be willing to help crowdfund F# Software Foundation members to work on this
The text was updated successfully, but these errors were encountered:
@dsyme In that case for C# class it would be possible to have private constructor and public deconstuctor. Would be nice to have the same option for records (union types?) with private constructors. This solution will become more concise.
@dsyme the use cases for deconstructors in C# are a bit limited. Most C# devs I deal with agree that tuples don’t belong in an API with arbitrary consumers. Yet, F#/C# interop is often at just such a boundary. Also, much like F#, tuple usage in C# seems to be aimed at the 2,3,4 arity cases. Yet it’s not uncommon to have F# records with 10-15 fields. That smacks of a usability mismatch. But these are all in the realm of “optimal usage”. I don’t have a strong purely technical reason.
Provide predefined deconstructor for F# records
I propose we produce deconstructors automatically for F# records.
The new C# 7 language enhancements allow you to produce custom deconstructors to coincide with the introduction of the
ValueTuple<T>
type and tuple support in the language.It seems that it would make sense for F# records to provide a predefined deconstructor for F records either by default or via an attribute like
[<ProvidesDeconstructor>]
.The existing way of approaching this problem in F# is to roll your own deconstructor via a type extension, but records and deconstructors seem to go hand in hand.
Pros and Cons
The advantages of making this adjustment to F# are that:
The disadvantages of making this adjustment to F# are:
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
S
Related suggestions: (put links to reated suggestions here)
Affadavit (must be submitted)
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: