-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allow assigning arbitrary values when pattern matching #1378
Comments
One existing way would probably be to use an active pattern and an let f x =
let (|Otherwise|) _ = 1
match x with
| A v
| B & Otherwise v -> v + 1 |
@brianrourkeboll You can even pass the value as argument to this active pattern. let (|With|) v _ = v
let f x =
match x with
| A v
| B & With 1 v -> v + 1 |
I think parameterless total active patterns should only be allowed on functions ? See dotnet/fsharp#17190 |
Do you mean |
Merging cases that aren't the same is a dangerous thing to do, just make a function and reuse it. I don't think we should do this and I think adding it would be damaging to the language. module MyType =
let getValueOrDefault defaultValue m =
match m with
| CaseWithValue a -> a
| CaseWithoutValue -> defaultValue |
I propose we make it possible to assign arbitrary values in match statements, so that OR matching becomes a bit more versatile by allowing you to define default values for valueless cases; eg:
The existing way of approaching this problem in F# is to handle the cases separately
Pros and Cons
The advantages of making this adjustment to F# are the*
The disadvantages of making this adjustment to F# are
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S?
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick these items 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.
The text was updated successfully, but these errors were encountered: