I’ve written this piece of code:
module BddNode = struct type t = | BddLeaf of bool | BddNode of string * int * int let compare x y = match (x, y) with | BddLeaf bx, BddLeaf by -> compare bx by | BddLeaf _, BddNode _ -> -1 | BddNode _, BddLeaf _ -> 1 | BddNode (x1, x2, x3) , BddNode (y1, y2, y3) -> compare (x1, x2, x3) (y1, y2, y3) end module BddGraph = Map.Make(BddNode)
It compiles, but is it a way to automatically “derive” the OrderedType? I’ve found this stackoverflow answer: https://stackoverflow.com/questions/17173101/ordered-variant-types-and-subtypes-in-ocaml but this a bit old and it seems OCaml noticeably envolved from this time.
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)