I come from C# and find myself in love with the F# pattern matching syntax as it's simpler than C# switch
and way more useful. I like to use it as much as possible, is there a performance or any other downside to using it in weird ways like in this example?
match 0 with
|_ when a<b -> a
|_ -> b
In this particular example, there will be no performance penalty. It is very likely that performance penalty will also be absent in other cases, but to be absolutely sure you'll have to look at the generated code with something like ILSpy.
I must also add that as you use F#, you'll find that if/then/else
is also very nice. In C#, if/else
feels kinda awkward, because it can't be used as expression, but in F# it is not the case, and so the awkwardness soon disappears.
let x = if a < b then a else b
It even reads like plain English! :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With