caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Variants & structural ordering
@ 2008-02-05 16:59 Damien Guichard
  2008-02-05 17:25 ` Stéphane Lescuyer
  0 siblings, 1 reply; 7+ messages in thread
From: Damien Guichard @ 2008-02-05 16:59 UTC (permalink / raw)
  To: Damien Guichard, Liste de diffusion OCaml

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]


Thanks to all for your answers.

I am aware my code exemple is quite artificial, certainly integers are simpler in this particular case.

My more profound question was: are variants treated as an enumeration or not ?
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.
And it will not change in near future.

Ok, i can live with that.

- damien

[-- Attachment #2: Type: text/html, Size: 883 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Variants & structural ordering
@ 2008-02-05  8:21 Damien Guichard
  2008-02-05  9:47 ` [Caml-list] " Berke Durak
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Damien Guichard @ 2008-02-05  8:21 UTC (permalink / raw)
  To: Liste de diffusion OCaml

[-- Attachment #1: Type: text/plain, Size: 544 bytes --]


Hi everybody,

Typically, when you declare:

type card =
  | Card of int
  | Jack
  | Queen
  | King
  | Ace
  ;;

The relation you wish is:

Card(2) < ...< Card(10) < Jack < Queen < King < Ace

And that's what you get when using F#.

However when using OCaml here is what you get:

Jack < Queen < King < Ace < Card(2) < ...< Card(10)

And the work-around is: 

type card =
  | Card of int
  | Jack of unit
  | Queen of unit
  | King of unit
  | Ace of unit
  ;;

Is this a bug or a feature ?
Will it change in a foreseable future ?

- damien

[-- Attachment #2: Type: text/html, Size: 1238 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-02-07 15:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-05 16:59 [Caml-list] Variants & structural ordering Damien Guichard
2008-02-05 17:25 ` Stéphane Lescuyer
  -- strict thread matches above, loose matches on Subject: below --
2008-02-05  8:21 Damien Guichard
2008-02-05  9:47 ` [Caml-list] " Berke Durak
2008-02-05  9:48 ` Oliver Bandel
2008-02-05 15:04 ` Jon Harrop
2008-02-06  8:21 ` Michaël Grünewald
2008-02-07 15:50 ` Damien Doligez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).