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

Provide predefined deconstructor for F# records #537

Open
1 task
DamianReeves opened this issue Feb 12, 2017 · 4 comments
Open
1 task

Provide predefined deconstructor for F# records #537

DamianReeves opened this issue Feb 12, 2017 · 4 comments

Comments

@DamianReeves
Copy link

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:

  • 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] I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • [ 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
@voroninp
Copy link

voroninp commented Jun 8, 2018

Interesting whether F# would support then pattern matching via deconstuctors...

@dsyme
Copy link
Collaborator

dsyme commented Jun 8, 2018

I don't see any real reason not to do this - @pblasucci was there a particular reason for the thumbs-down?

@voroninp
Copy link

voroninp commented Jun 8, 2018

@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.

@pblasucci
Copy link

pblasucci commented Jun 8, 2018

@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.

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

No branches or pull requests

4 participants