At least, is it a way to write the last case of the match like: | BddNode vy , BddNode vx -> compare vx vy
?
(with this exact syntax, the compiler complains that the BddNode constructor ask for 3 parameters)
type t =
| BddLeaf of bool
| BddNode of string * int * int [@@deriving ord]
and then you’ll get a compare function for free (the default for tuple is a lexicographic order, for enumeration it is what you would expect - for a type foo = A | B, you get A < B )
The way you have defined it, the constructor BddNode expects 3 arguments. They cannot be collected into a tuple vx in the way you tried above. You could define another constructor BddNode1 of (string * int *int) which is a one-argument constructor that takes a tuple (note the parentheses). With that you could do the match as you wanted. Unfortunately, OCaml prints values of BddNode and BddNode1 in the exact same way. Afair there are differences in the representation of values of these types in memory but i can never remember the details.