fsharp / fsharp/fslang-suggestions

Provide predefined deconstructor for F# records

Open
#537 4 comments 9 reactions 0 assignees View on GitHub
approved-in-principle area: interop
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

# 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](https://msdn.microsoft.com/en-us/magazine/mt790184.aspx) to coincide with the introduction of the `ValueTuple` 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 `[]`.

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](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [ x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) 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

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository files or tests are identified in the issue. Start by reviewing the linked C# 7 deconstructor reference and the existing type-extension approach; clarify the default-versus-attribute design and the behavior for single-field records before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.