let's say I have
type t = A of int | B of int
let xx = A(2);;
let yy = A(3);;
and I want to test if the constructors of xx and yy are equal, is there an easy way to do this ? Instead of having to
match xx with
A _ ->
(match yy with A _ -> true | B _ -> false)
| B _ ->
(match yy with A _ -> false | B _ -> true);;
which gets quite messy when there many constructors on a type
You can rewrite the above to, somewhat simpler:
match xx, yy with
| A _, A _
| B _, B _ -> true
| (A _ | B _), _ -> false
but I'm not aware of a solution without enumerating all the constructors.
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