Reputation: 12107
Right now, when I have a Result type, it seems like I need to do a match to find if it is ok, or not.
So, I am trying to simplify this to be able to use if, like that:
let a : Result<string, string> = ...
if a.IsOk then ....
Here is my attempt
[<AutoOpen>]
module ResultHelper =
type Result with
member this.IsOk =
match this with
| Ok _ -> true
| Error _ -> false
but this will not compile.
Using:
type Result<_, _> with
doesn't help either
How can I achieve this?
Upvotes: 1
Views: 88
Reputation: 80744
The correct syntax is to give the type parameters names. As a bonus, this will allow you to refer to them in the code if you need to.
type Result<'a, 'b> with
member this.IsOk =
match this with
| Ok _ -> true
| Error _ -> false
P.S. For the future, please note that "will not compile" is not a good description of a problem. Please make sure to always include the full error message.
Upvotes: 3