caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Francois Berenger <berenger@riken.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Stability of order between polymorphic variants
Date: Thu, 05 Sep 2013 11:18:34 +0900	[thread overview]
Message-ID: <5227E9FA.1020301@riken.jp> (raw)
In-Reply-To: <CAN=ouMQ+vC1uR4M3EqS8odZ2M+ohRY-wx7hD9ZA2Dz_c5wPzrA@mail.gmail.com>

On 09/05/2013 11:11 AM, Anthony Tavener wrote:
> Addendum: On a 32b arch, those names will wrap.

Why not write a to_int for your type
and then a specialized comparator using it?

> On Wed, Sep 4, 2013 at 8:06 PM, Anthony Tavener
> <anthony.tavener@gmail.com <mailto:anthony.tavener@gmail.com>> wrote:
>
>     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 <mailto: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
>
>
>


  reply	other threads:[~2013-09-05  2:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-05  0:17 Daniel Bünzli
2013-09-05  2:06 ` Anthony Tavener
2013-09-05  2:11   ` Anthony Tavener
2013-09-05  2:18     ` Francois Berenger [this message]
2013-09-05  2:31       ` Anthony Tavener
2013-09-05  7:47         ` Stéphane Glondu
2013-09-05  8:24 ` Jacques Garrigue
2013-09-05  8:39   ` Mark Shinwell
2013-09-05  9:26 ` Jeremy Yallop
2013-09-05 14:46   ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5227E9FA.1020301@riken.jp \
    --to=berenger@riken.jp \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).