Shorter way to create an Ordered type?

You are probably looking for https://github.com/ocaml-ppx/ppx_deriving (especially the plugin ord). This allows you to simply write :

  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 )

5 Likes