fsharp / fsharp/fslang-suggestions
Allow access to record type constructors in F#
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
[RFC FS-1073](https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1073-record-constructors.md)
### F# has concise syntax for defining records:
```fsharp
type PensionData =
{ Name:string; ProbableNumberOfYearsUntilRetirement:int }
```
### Creation of records in C# is easy, using the constructor:
```csharp
PensionData r = PensionData("Adam",10)
```
This is convenient as to enter the data you can just type the class name, a bracket, and intellisense will tell you what the fields should be.
### Creating records in F# is clunky, because the constructor is not accessible:
```fsharp
let r = { Name = "Adam"; ProbableNumberOfYearsUntilRetirement = 10 }
```
The disadvantages are:
- Verbose syntax compared to C#, with all field names needing to be written out.
- Poor intellisense support. Without the binding to `r` it would be hard to determine the type of the record. In order to enter the record, you have to know the field names, and intellisense does not assist.
- Activation of an unreliable type-inference system which relies on guesswork: record type inference guesses types based on field names entered. This requires an annotation to solve, which is extra verbosity.
- The type is not clear when reading code; to work out the type, the reader must mentally implement the algorithm in the compiler, which is more work than reading a single word.
## Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions:
## Affidavit (please submit!)
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 or my company would be willing to help implement and/or test this
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.