Pattern violation

I come from C # and fall in love with the F # pattern matching syntax as it is simpler than C # switch and more useful. I like to use it as much as possible, is there any performance or some other disadvantage to use it in strange ways like in this example?

 match 0 with |_ when a<b -> a |_ -> b 
+6
source share
1 answer

In this particular example, there will be no performance penalty. It is very likely that in other cases there will also be no performance penalty, but to be absolutely sure, you will have to look at the generated code with something like ILSpy.

I should also add that when using F # you will find that if/then/else also very nice. In C #, if/else feels awkward because it cannot be used as an expression, but in F # it is not, and therefore the inconvenience will soon disappear.

  let x = if a < b then a else b 

It even reads like plain English !:-)

+6
source

Source: https://habr.com/ru/post/988057/


All Articles