Make it possible to deconstruct multi-field Discriminated Unions by naming multiple fields
Right above https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/discriminated-unions#unwrapping-discriminated-unions, it is documented that we can match a discriminated unions by a single field name.
type Shape =
| Rectangle of width : float * length : float
| Circle of radius : float
| Prism of width : float * float * height : float
let getShapeWidth shape =
match shape with
| Rectangle(width = w) -> w
| Circle(radius = r) -> 2. * r
| Prism(width = w) -> w
However, as soon as we try to match more than one field,
let getContainedSpace shape =
match shape with
| Rectangle(w, l) -> w * l
| Circle(r) -> System.Math.PI * r ** 2.
| Prism(w, l, height = h) -> w * l * h // The "height = " causes these errors
// error FS0010: Unexpected symbol '=' in pattern. Expected ')' or other token.
// error FS0583: Unmatched '('
// error FS0010: Unexpected symbol '=' in pattern. Expected ')' or other token.
// error FS0583: Unmatched '('
// error FS0039: The value or constructor 'h' is not defined.
This feature is so incomplete!
Pros and Cons
The advantages of making this adjustment to F# are
- Extending an existing feature to satisfy more use cases
- More consistency between constructing and deconstructing a discriminated union. This is already allowed for the construction side.
The disadvantages of making this adjustment to F# are (none)
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
Make it possible to deconstruct multi-field Discriminated Unions by naming multiple fields
Right above https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/discriminated-unions#unwrapping-discriminated-unions, it is documented that we can match a discriminated unions by a single field name.
However, as soon as we try to match more than one field,
This feature is so incomplete!
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantages of making this adjustment to F# are (none)
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.