I haven't looked at how the compare happens for polyvariants, but I assume it's going to treat them as integers. And the integer value of the polymorphic variants is a simple hashing-type function (byterun/hash.c: caml_hash_variant). A multiplication by 223 is involved for each character of the variant name, so with a long enough name, compared to the integer size, you'll get wraparound. The short names you have there are okay.

I'd be uncomfortable relying on this ordering, but I can imagine it would make some things a lot simpler...



On Wed, Sep 4, 2013 at 6:17 PM, Daniel Bünzli <daniel.buenzli@erratique.ch> wrote:
Hello,

I have this type

  type weight = [ `W100 | `W200 | `W300 | `W400 | `W500 | `W600 | `W700 | `W800 | `W900 ]

In the current compiler it has the property that `Wx00 < `Wy00 if x < y.

The question is, is the order between polymorphic variants an invariant provided by the compiler or is it subject to change ?

Best,

Daniel



--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs