From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.9 required=5.0 tests=DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id C6097BC6C for ; Tue, 5 Feb 2008 09:18:59 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEuqp0fAXQInh2dsb2JhbACCPTONRAEBAQgKKZwB X-IronPort-AV: E=Sophos;i="4.25,306,1199660400"; d="scan'208,217";a="6896648" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Feb 2008 09:18:59 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m158Iw2j020859 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 5 Feb 2008 09:18:59 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIaqp0fB/BYelmdsb2JhbACCPTONRAEBAQEHBAYHChEHnAI X-IronPort-AV: E=Sophos;i="4.25,306,1199660400"; d="scan'208,217";a="22196219" Received: from smtp23.orange.fr ([193.252.22.30]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Feb 2008 09:18:58 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2341.orange.fr (SMTP Server) with ESMTP id 3560E1C02544 for ; Tue, 5 Feb 2008 09:18:58 +0100 (CET) Received: from Thinkpad-R60 (Mix-Lyon-303-2-225.w193-248.abo.wanadoo.fr [193.248.44.225]) by mwinf2341.orange.fr (SMTP Server) with SMTP id 2D24D1C02531 for ; Tue, 5 Feb 2008 09:18:45 +0100 (CET) X-ME-UUID: 20080205081845185.2D24D1C02531@mwinf2341.orange.fr Date: Tue, 5 Feb 2008 09:21:21 +0100 From: "Damien Guichard" To: "Liste de diffusion OCaml" Subject: Variants & structural ordering X-mailer: Foxmail 5.0 [-fr-] Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=====003_Dragon688863810154_=====" Message-Id: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> X-Miltered: at concorde with ID 47A81BF2.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; damien:01 guichard:01 variants:01 ocaml:01 work-around:01 bug:01 damien:01 ocaml:01 work-around:01 bug:01 int:01 int:01 unit:03 unit:03 structural:04 This is a multi-part message in MIME format. --=====003_Dragon688863810154_===== Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit 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 --=====003_Dragon688863810154_===== Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit

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
--=====003_Dragon688863810154_=====-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id BBF27BC6C for ; Tue, 5 Feb 2008 10:47:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGK/p0fAXQInh2dsb2JhbACQKgEBAQgKKYEVmwE X-IronPort-AV: E=Sophos;i="4.25,306,1199660400"; d="scan'208";a="7610219" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 Feb 2008 10:47:36 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m159lUo5025264 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 5 Feb 2008 10:47:36 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAOq+p0fBL1AZh2dsb2JhbACQKgEBAQgKKYEVmwA X-IronPort-AV: E=Sophos;i="4.25,306,1199660400"; d="scan'208";a="8764132" Received: from gw.exalead.com (HELO exalead.com) ([193.47.80.25]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Feb 2008 10:47:35 +0100 Received: from [192.168.204.148] (madpc064.exalead.com [192.168.204.148]) (authenticated bits=0) by exalead.com (8.14.0/8.14.0) with ESMTP id m159lWEo029013; Tue, 5 Feb 2008 10:47:34 +0100 Message-ID: <47A830B4.8080801@exalead.com> Date: Tue, 05 Feb 2008 10:47:32 +0100 From: Berke Durak User-Agent: Thunderbird 1.5.0.10 (X11/20070221) MIME-Version: 1.0 To: Damien Guichard , Caml-list List Subject: Re: [Caml-list] Variants & structural ordering References: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> In-Reply-To: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 47A830B3.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; berke:01 durak:01 berke:01 durak:01 variants:01 damien:01 guichard:01 ocaml:01 work-around:01 bug:01 constructors:01 integers:01 constructors:01 ad-hoc:01 ocaml:01 Damien Guichard a écrit : > Hi everybody, Hello > 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#. Thanks for this bit of knowledge about 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 ? Neither: You are not supposed to assume anything on the way compare orders non-primitive types. Constructors without arguments are represented as integers, which, as primitive types, come before blocks, which are used to represent the values of constructors with arguments. The "compare" functions give an ad-hoc order, the only guarantee being that it will be a good ordering. I think you can safely assume that it won't change accross Ocaml releases (unless you start using a new VM.) In practice, people often assume that the components of tuples and records are compared in the same order as their components are given. Relying on the order of enumerated types is more risky: you provide a good example of this. > Will it change in a foreseable future ? I really don't think so and even if it did, there is no reason why it would change in the way that would be useful to you in that particular case, and even then, it would be risky to depend on that behaviour, and, besides, what's the point? Simply use something like: let max_card = 10 let int_of_card = function | Card n -> assert(n < max_card); n | Jack -> max_card | Queen -> max_card + 1 | King -> max_card + 2 let compare c1 c2 = compare (int_of_card c1) (int_of_card c2) -- Berke DURAK From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 9ACB8BC6C for ; Tue, 5 Feb 2008 10:48:59 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAHK/p0fAbSoIc2dsb2JhbACQHQ0BCgQGCR2cHA X-IronPort-AV: E=Sophos;i="4.25,306,1199660400"; d="scan'208";a="6903184" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Feb 2008 10:48:59 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m159mtIH009383 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 5 Feb 2008 10:48:59 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAHK/p0fAbSoIc2dsb2JhbACQHQ0BCgQGCR2cHA X-IronPort-AV: E=Sophos;i="4.25,306,1199660400"; d="scan'208";a="6903181" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Feb 2008 10:48:54 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from einhorn.in-berlin.de (localhost [127.0.0.1]) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id m159mss8017374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 5 Feb 2008 10:48:54 +0100 Received: (from www-data@localhost) by einhorn.in-berlin.de (8.13.6/8.13.6/Submit) id m159mrUb017371 for caml-list@inria.fr; Tue, 5 Feb 2008 10:48:53 +0100 X-Authentication-Warning: einhorn.in-berlin.de: www-data set sender to oliver@first.in-berlin.de using -f Received: from dslb-088-073-107-081.pools.arcor-ip.net (dslb-088-073-107-081.pools.arcor-ip.net [88.73.107.81]) by webmail.in-berlin.de (IMP) with HTTP for ; Tue, 5 Feb 2008 10:48:53 +0100 Message-ID: <1202204933.47a83105b01ea@webmail.in-berlin.de> Date: Tue, 5 Feb 2008 10:48:53 +0100 From: Oliver Bandel To: Liste de diffusion OCaml Subject: Re: [Caml-list] Variants & structural ordering References: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> In-Reply-To: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Miltered: at discorde with ID 47A83107.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bandel:01 in-berlin:01 variants:01 damien:01 guichard:01 bug:01 oliver:01 oliver:01 caml-list:01 structural:04 feature:09 ciao:11 von:84 ordering:80 orange:78 Zitat von Damien Guichard : [...] > Is this a bug or a feature ? [...] It's F# ;-) Ciao, Oliver From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 3509ABC6C for ; Tue, 5 Feb 2008 16:09:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAGQKqEfUnw7UhWdsb2JhbACCNo12AQEBCAQGBwgTB50F X-IronPort-AV: E=Sophos;i="4.25,308,1199660400"; d="scan'208";a="6926246" Received: from ptb-relay01.plus.net ([212.159.14.212]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Feb 2008 16:09:09 +0100 Received: from [80.229.56.224] (helo=beast.local) by ptb-relay01.plus.net with esmtp (Exim) id 1JMPQ4-0004JA-6Q for caml-list@yquem.inria.fr; Tue, 05 Feb 2008 15:09:08 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Variants & structural ordering Date: Tue, 5 Feb 2008 15:04:38 +0000 User-Agent: KMail/1.9.7 References: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> In-Reply-To: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802051504.38263.jon@ffconsultancy.com> X-Plusnet-Relay: c221ccecf808347c1ad8a4a727ed6ebc X-Spam: no; 0.00; variants:01 damien:01 guichard:01 ocaml's:01 haskell's:01 afaict:01 ocaml:01 ocaml's:01 achilles:98 heel:98 grief:98 frog:98 equality:01 polymorphic:01 wrote:01 On Tuesday 05 February 2008 08:21:21 Damien Guichard wrote: > 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#. Comparison is OCaml's achilles heel and this is one (minor) manifestation of that. The ability to develop a program and break a use of polymorphic comparison buried within it without knowing is far more serious and has caused many people untold grief in the past. SML's equality types are a slight improvement but F# and Haskell's solutions are the best way forward AFAICT. OCaml will never be fixed in this sense but, hopefully, a next-generation FPL implementation will solve these problems without sacrificing OCaml's other benefits. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 72C4DBC6C for ; Tue, 5 Feb 2008 17:57:17 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAALMjqEfAXQInh2dsb2JhbACCPDSNPAEBAQgKKZ0F X-IronPort-AV: E=Sophos;i="4.25,308,1199660400"; d="scan'208,217";a="8793870" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Feb 2008 17:57:17 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m15GvGir014738 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 5 Feb 2008 17:57:16 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAACskqEdQDPJhimdsb2JhbACCPDSNPAEBAQgEBgcKEQedBg X-IronPort-AV: E=Sophos;i="4.25,308,1199660400"; d="scan'208,217";a="7641505" Received: from smtp23.orange.fr ([80.12.242.97]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 Feb 2008 17:57:16 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2354.orange.fr (SMTP Server) with ESMTP id CE4167000EA9 for ; Tue, 5 Feb 2008 17:57:15 +0100 (CET) Received: from Thinkpad-R60 (Mix-Lyon-303-4-15.w193-248.abo.wanadoo.fr [193.248.106.15]) by mwinf2354.orange.fr (SMTP Server) with SMTP id DE06A7000C0E; Tue, 5 Feb 2008 17:57:14 +0100 (CET) X-ME-UUID: 20080205165714909.DE06A7000C0E@mwinf2354.orange.fr Date: Tue, 5 Feb 2008 17:59:50 +0100 From: "Damien Guichard" To: "Damien Guichard" , "Liste de diffusion OCaml" Subject: Re: [Caml-list] Variants & structural ordering X-mailer: Foxmail 5.0 [-fr-] Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=====003_Dragon831413644783_=====" Message-Id: <20080205165714.DE06A7000C0E@mwinf2354.orange.fr> X-Miltered: at concorde with ID 47A8956C.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; damien:01 guichard:01 variants:01 integers:01 variants:01 enumeration:01 ocaml:01 algebra:01 enumeration:01 damien:01 integers:01 ocaml:01 algebra:01 caml-list:01 artificial:01 This is a multi-part message in MIME format. --=====003_Dragon831413644783_===== Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit 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 --=====003_Dragon831413644783_===== Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit
 
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
--=====003_Dragon831413644783_=====-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id EF95CBC6C for ; Tue, 5 Feb 2008 18:25:35 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANkqqEfAXQImh2dsb2JhbACQLAEBAQgKKZZohgA X-IronPort-AV: E=Sophos;i="4.25,308,1199660400"; d="scan'208";a="8795554" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Feb 2008 18:25:35 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m15HPZOc031239 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 5 Feb 2008 18:25:35 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEgqqEdA6aa2i2dsb2JhbACQLAEBAQgEBAkKEQWWbIYA X-IronPort-AV: E=Sophos;i="4.25,308,1199660400"; d="scan'208";a="22234880" Received: from py-out-1112.google.com ([64.233.166.182]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Feb 2008 18:25:34 +0100 Received: by py-out-1112.google.com with SMTP id u52so3839416pyb.10 for ; Tue, 05 Feb 2008 09:25:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=B2C8kHhRcGu/vXskw8RTBVkNgkpAe/MAh4qjAM3Ho9E=; b=Ob8+7ODBErDY/Kc2cqGhQcx75RA1gFo3hI4rp6mrq0XwCO+x1AaM3SkdTV+5Y4Rtn/D3TsqmxJo2VMErFp4vVSTfcIxPwLHEy9Y/wCB5dCsbbVYDx3zL5hDGjTilWhEW2kJBYqdgVg3VjS2VqAfdFszfYzgA33y+gi6Py8uZcBk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=EhTNmYIreb8wXa2n6OIcKgrefMCfvOLdVZbeB/p4KMPoDr7VUqclHjfJzRp/SjofT8kcAtCe317N6H8udwvmMaoALs+3xp33mIfdPxcfMs/K8tvCdUwOG1Klnj6p4B8ONKLhmxdxWNhwIreYxsDpIogP9j1iiaCCI3D+9x1aOAs= Received: by 10.65.180.9 with SMTP id h9mr16166992qbp.41.1202232332442; Tue, 05 Feb 2008 09:25:32 -0800 (PST) Received: by 10.65.232.4 with HTTP; Tue, 5 Feb 2008 09:25:32 -0800 (PST) Message-ID: Date: Tue, 5 Feb 2008 18:25:32 +0100 From: "=?ISO-8859-1?Q?St=E9phane_Lescuyer?=" Sender: steki.kun@gmail.com To: "Damien Guichard" Subject: Re: [Caml-list] Variants & structural ordering Cc: "Liste de diffusion OCaml" In-Reply-To: <20080205165714.DE06A7000C0E@mwinf2354.orange.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20080205165714.DE06A7000C0E@mwinf2354.orange.fr> X-Google-Sender-Auth: 38f34f89b8207e11 X-Miltered: at discorde with ID 47A89C0F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lri:01 variants:01 damien:01 guichard:01 ocaml:01 variants:01 algebra:01 enumeration:01 berke:01 constructors:01 lri:01 polymorphic:01 caml-list:01 variant:02 caml:02 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 [http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html], 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 instance. -- St=E9phane L. http://www.lri.fr/~lescuyer From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 81779BC6C for ; Wed, 6 Feb 2008 09:22:04 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADT9qEfAXQInh2dsb2JhbACBWY5YAQEBCAopgRWcDw X-IronPort-AV: E=Sophos;i="4.25,311,1199660400"; d="scan'208";a="22277039" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 06 Feb 2008 09:22:04 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m168M3Ph009647 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 6 Feb 2008 09:22:03 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPz8qEfUGyoji2dsb2JhbACBWY5YAQEBCAQGCQgRB4EVnBA X-IronPort-AV: E=Sophos;i="4.25,311,1199660400"; d="scan'208";a="7689691" Received: from smtp5-g19.free.fr ([212.27.42.35]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Feb 2008 09:22:03 +0100 Received: from smtp5-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp5-g19.free.fr (Postfix) with ESMTP id F371F3F61B3; Wed, 6 Feb 2008 09:22:02 +0100 (CET) Received: from Llea.celt.neu (ron34-3-82-236-236-194.fbx.proxad.net [82.236.236.194]) by smtp5-g19.free.fr (Postfix) with ESMTP id 7B52E3F6181; Wed, 6 Feb 2008 09:22:02 +0100 (CET) Received: from Llea.celt.neu (localhost [127.0.0.1]) by Llea.celt.neu (8.14.2/8.13.8) with ESMTP id m168Lm01001053; Wed, 6 Feb 2008 09:21:48 +0100 (CET) (envelope-from michaelgrunewald@yahoo.fr) Received: (from michael@localhost) by Llea.celt.neu (8.14.2/8.13.8/Submit) id m168Llcd001052; Wed, 6 Feb 2008 09:21:47 +0100 (CET) (envelope-from michaelgrunewald@yahoo.fr) X-Authentication-Warning: Llea.celt.neu: michael set sender to michaelgrunewald@yahoo.fr using -f To: "Damien Guichard" Cc: "Liste de diffusion OCaml" Subject: Re: [Caml-list] Variants & structural ordering References: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> From: michaelgrunewald@yahoo.fr (=?iso-8859-15?Q?Micha=EBl_Gr=FCnewald?=) Date: Wed, 06 Feb 2008 09:21:47 +0100 In-Reply-To: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> (Damien Guichard's message of "Tue\, 5 Feb 2008 09\:21\:21 +0100") Message-ID: <864pcmze90.fsf@Llea.celt.neu> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable X-Miltered: at concorde with ID 47A96E2B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; variants:01 damien:01 guichard:01 ocaml:01 work-around:01 bug:01 ocaml:01 vice-versa:01 caml-list:01 int:01 int:01 writes:01 conventions:02 arbitrary:02 define:02 "Damien Guichard" writes: > Hi everybody, >=20=20 > Typically, when you declare: >=20=20 > type card =3D > | Card of int > | Jack > | Queen > | King > | Ace > ;; >=20=20 > The relation you wish is: >=20=20 > Card(2) < ...< Card(10) < Jack < Queen < King < Ace >=20=20 > And that's what you get when using F#. >=20=20 > However when using OCaml here is what you get: >=20=20 > Jack < Queen < King < Ace < Card(2) < ...< Card(10) >=20=20 > And the work-around is: >=20=20 > type card =3D > | Card of int > | Jack of unit > | Queen of unit > | King of unit > | Ace of unit > ;; >=20=20 > Is this a bug or a feature ? > Will it change in a foreseable future ? Conventions are always a bit arbitrary, aren't they? To me, the natural order with cards are: Card(7) < Card(8) < Queen < King < Card(10)< Ace < Card(9) < Jack and Card(7) < Card(8) < Card(9) < Jack < Queen < King < Card(10)< Ace (yes there are two natural orders). Furthermore, I tried your program on a host whose native charset is KOBAIA-8 (a weird variation on EBCDIC), hold your breath: F# behaves there just like OCaml does on your host, and vice-versa! Computers are good at doing what they are told to, so why don't you tell them? The only purpose of a generic `compare' procedure os the easy use of `Set.Make' and `Map.Make' with random types, isnt't it? It is very bad to assume it giving any sensible order on non basic types, you sure have to define `sensible' yourself. --=20 Micha=EBl From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id E3274BC6C for ; Thu, 7 Feb 2008 16:50:07 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAA+3qkfAXQImh2dsb2JhbACQMQEBAQgKKZta X-IronPort-AV: E=Sophos;i="4.25,316,1199660400"; d="scan'208";a="22361117" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 07 Feb 2008 16:50:07 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m17Fo65M027587 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 7 Feb 2008 16:50:07 +0100 X-IronPort-AV: E=Sophos;i="4.25,316,1199660400"; d="scan'208";a="22361116" Received: from macabane.inria.fr ([128.93.8.160]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA; 07 Feb 2008 16:50:06 +0100 Message-Id: From: Damien Doligez To: Liste de diffusion OCaml In-Reply-To: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v915) Subject: Re: [Caml-list] Variants & structural ordering Date: Thu, 7 Feb 2008 16:50:08 +0100 References: <20080205081845.2D24D1C02531@mwinf2341.orange.fr> X-Mailer: Apple Mail (2.915) X-Miltered: at discorde with ID 47AB28AF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; damien:01 damien:01 variants:01 guichard:01 doligez:01 doligez:01 wrote:01 caml-list:01 structural:04 guess:04 comparison:05 inria:06 function:08 ace:90 ace:90 On 2008-02-05, at 09:21, Damien Guichard wrote: > The relation you wish is: > > Card(2) < ...< Card(10) < Jack < Queen < King < Ace That's funny, depending on the suit I would wish one of the following: Card(7) < ... < Card(9) < Jack < Queen < King < Card(10) < Ace Card(7) < Card(8) < Queen < King < Card(10) < Ace < Card(9) < Jack ... And no fixed comparison function will ever be able to guess whether you're comparing trumps. -- the other Damien