fsharp / fsharp/fslang-suggestions
Optional arguments in DU constructors
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
Often in DU cases there are settings that sometimes need specifying and are represented as option types:
```fsharp
type TextElement =
| String of text:string * fontSize: float option * color: Color option
| PageBreak
let s1 = String("Normal text.", None, None)
let s2 = String("Blue text.", None, Some Color.Blue)
```
These should be writable using optional argument constructor syntax:
```fsharp
type TextElement =
| String of text:string * ?fontSize: float * ?color: Color
| PageBreak
let s1 = String("Normal text.")
let s2 = String("Blue text.", color = Color.Blue)
```
Related suggestions: https://github.com/fsharp/fslang-suggestions/issues/852 and related, which would allow making DU constructors private and implementing separate constructors as static methods with optional arguments.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the proposed DU constructor syntax and the related suggestions in issues #852 and related. Define what optional arguments should mean for discriminated-union cases, including the shown construction examples; no implementation files or tests are identified in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100