# Shorter way to create an Ordered type?

**URL:** <https://discuss.ocaml.org/t/shorter-way-to-create-an-ordered-type/5382>\
**Category:** Learning\
**Created:** [March 26, 2020, 9:54pm UTC](https://discuss.ocaml.org/t/shorter-way-to-create-an-ordered-type/5382 "2020-03-26T21:54:32Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![sebbes](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sebbes/32/1997_2.png) [@sebbes](https://discuss.ocaml.org/u/sebbes)\
**Post date:** [March 26, 2020, 9:54pm UTC](https://discuss.ocaml.org/t/shorter-way-to-create-an-ordered-type/5382/1 "2020-03-26T21:54:32Z")

</div>

Hello!

I’ve written this piece of code:

```auto
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](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)

---

_[View the full topic](https://discuss.ocaml.org/t/shorter-way-to-create-an-ordered-type/5382)._
