-
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 returning bool instead of unit option for partial active patterns #1041
Comments
I have often found myself wanting this. |
One of the problems is we assert an It might be technically possible to make this work: let (|CaseInsensitive|_|) (pattern: string) (value: string) : bool =
String.Equals(value, pattern, StringComparison.OrdinalIgnoreCase) or of course we could use an attribute. |
I'll marked this as approved in principle, it's pretty reasonable to want this. |
Struct active patterns right now require |
In principle I'd like to, and I'd like to see this prototyped for both cases. In general it's actually not backwards compatible strictly, since without the option type is inferred from the |
@dsyme Assuming we could have anonymous union types in future, would initially inferring something like |
@auduchinok Existing implementations may be broken if another type than option is used for inference, like when the body only contains calls to generic functions. Instead, we could modify type checking and default to option if bool or voption are not inferred from the result. |
If we go down the
I've just had a look at this, and, as was mentioned elsewhere, the current ordering of type checking operations does make it non-trivial. My first impression of the annotation solution was that it should be fairly easy to implement. |
@vzarytovskii I think this can be closed ? dotnet/fsharp#16473 |
Yeah, thanks, I was waiting until insertion is done. |
Allow returning bool instead of unit option for partial active patterns
I propose we allow returning bool from partial active patterns that don't return a significant value apart from "matches" / "doesn't match".
The existing way of approaching this problem in F# is to return
Some ()
if the value matches andNone
if it doesn't.For example the active pattern for the following:
would currently be written as:
With this proposal, it could be written as:
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantages of making this adjustment to F# are
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions:
ValueSome ()
would still result in worse IL thantrue
.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.
The text was updated successfully, but these errors were encountered: