-
Notifications
You must be signed in to change notification settings - Fork 793
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
Suggestion: Allow active patterns in arguments of primary constructors #12720
Comments
Hi @En3Tho! Changes to the language need to go through fslang-suggestions instead of being raised here. Would you mind opening this suggestion there? |
@baronfel Yeah. I just wasn't really sure if this is a bug or a feature request actually. I believe it does have a smell of a bug but maybe I'm missing something important. What do you think? |
I went to go look in the parser and explicitly only a subset of simple patterns are allowed, which suggests to me that it was a design decision rather than an oversight. To me that means a language change is needed. |
Yeah, the spec (§8.6.1) says nested patterns can't be used in primary constructors:
|
Curious. Wonder why that decision was made. @dsyme can you please tell us about it? I don't know when exactly that decision was made but does it have an important meaning now? This behavior seems sort of outstanding. |
IIRC the reason is that the pattern can fail to match, and according to the verifiability rules of .NET IL we couldn't codegen the exception-raising before the Things may have changed and it's now possible to do this (partly because verifiability is less of a concern), I'm not sure. |
In any case yes please add to fslang-suggestions |
For some reason they don't work... Or some kind of workaround is needed ?
This is partially motivated by C# discussion of !! feature. In F# we can easily make it much readable and explicit by using ActivePatterns but for some reasons do not work with PrimaryConstructors or a workaround is needed.
So those a kinda related fsharp/fslang-suggestions#966 and fsharp/fslang-suggestions#1014 (look at active patterns example below)
The text was updated successfully, but these errors were encountered: