Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Variants & structural ordering
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-02-05 (17:25)
From: Stéphane_Lescuyer <lescuyer@l...>
Subject: Re: [Caml-list] Variants & structural ordering
2008/2/5 Damien Guichard <>:
> And the answer is: OCaml variants are certainly treated as an initial
> algebra, but not exactly as an enumeration, thus their relative order is not
> meaningfull to the compare function.

Actually it *is* meaningful, but as Berke pointed out, constant
constructors and variant expecting some arguments are treated (and
ordered) separately.
This is explained in detail in Sec. 18.3.4 of the manual
[], and this
is why adding dummy arguments of type unit does the trick.
My point is that it's not as bad as it looks, since you have a way to
"control" (or at least predict) what the order between your different
values will be. This is a difference with polymorphic variants for
Stéphane L.