I'm just curious, these two functions would do the same thing. But which one should I use?
let f a =
match a with
b -> a;;
let f a =
match a with
b -> b;;
Or it just depends on your preference?
I feel the second one would be better but I'm not sure.
Performance wise there is no difference. Style-wise b -> a is a bit problematic because you have an unused variable b. _ -> a would make more sense. Other than that, it's just preference.
Personally I would prefer _ -> a over b -> b because it doesn't introduce an extra variable.
PS: I assume in your real code there are more cases than just b - otherwise you could just write let f a = a.
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