From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id EE00C820A1 for ; Thu, 5 Sep 2013 04:06:17 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of anthony.tavener@gmail.com) identity=pra; client-ip=74.125.83.47; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="anthony.tavener@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of anthony.tavener@gmail.com designates 74.125.83.47 as permitted sender) identity=mailfrom; client-ip=74.125.83.47; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="anthony.tavener@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ee0-f47.google.com) identity=helo; client-ip=74.125.83.47; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="postmaster@mail-ee0-f47.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqcBALHlJ1JKfVMvk2dsb2JhbABbgzxRrnyKCYhBgSEIFg4BAQEBBwsLCRQEJIIkAQEEAUABGxILAQMBCwYFBAcaISIBEQEFAQoSBhMSh10BAwkGDJwljFCDBYQzChknAwpkiDsBBQyPUAQHhB0DiTWKZoNagS+JEIU+GCmEZx0 X-IPAS-Result: AqcBALHlJ1JKfVMvk2dsb2JhbABbgzxRrnyKCYhBgSEIFg4BAQEBBwsLCRQEJIIkAQEEAUABGxILAQMBCwYFBAcaISIBEQEFAQoSBhMSh10BAwkGDJwljFCDBYQzChknAwpkiDsBBQyPUAQHhB0DiTWKZoNagS+JEIU+GCmEZx0 X-IronPort-AV: E=Sophos;i="4.90,843,1371074400"; d="scan'208";a="31537858" Received: from mail-ee0-f47.google.com ([74.125.83.47]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 05 Sep 2013 04:06:17 +0200 Received: by mail-ee0-f47.google.com with SMTP id d49so563896eek.6 for ; Wed, 04 Sep 2013 19:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=QqZjkZTxebtJ8XRXC85wpCVKHEynqwX3dYOuZdOST4k=; b=x17pRJDhisxe8msIO09lD4vEo6KOD6JqX0nMkkuqN6p0uM8ptcH5skkGXosUu3ruuM m5DdMc43P8V5l9iTTi9BxZLfHHbhDoMVtywEBxT/JXDdbrEQTsRY2pXu8NExAVQDDMmC 75jGprUTODG2S3DwdoPLn1v+JFfGx0TmodkIHqfbc9CWHP0nYjsjUNOuRUrKBD8X654g HRhsyKjVp/vYsgswsHHzONL5urgccMdULhSdBgNDjYQW7Eym4RPm0t9HGrtr78Xqn/lO uQVtTmgH/vco7rKXZBW+Fl74TE+U3/D3dqxrVgq9tZeKsu9OOEBMFvnsTioTkCZzcqlL nJWA== MIME-Version: 1.0 X-Received: by 10.14.99.193 with SMTP id x41mr59309eef.52.1378346777063; Wed, 04 Sep 2013 19:06:17 -0700 (PDT) Received: by 10.14.10.68 with HTTP; Wed, 4 Sep 2013 19:06:16 -0700 (PDT) In-Reply-To: References: Date: Wed, 4 Sep 2013 20:06:16 -0600 Message-ID: From: Anthony Tavener To: =?ISO-8859-1?Q?Daniel_B=FCnzli?= Cc: caml list Content-Type: multipart/alternative; boundary=001a11c36fe8065fe604e5995e46 Subject: Re: [Caml-list] Stability of order between polymorphic variants --001a11c36fe8065fe604e5995e46 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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=FCnzli wrote: > Hello, > > I have this type > > type weight =3D [ `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 > --001a11c36fe8065fe604e5995e46 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I haven't looked at how the compare happens for polyva= riants, but I assume it's going to treat them as integers. And the inte= ger value of the polymorphic variants is a simple hashing-type function (by= terun/hash.c: caml_hash_variant). A multiplication by 223 is involved for e= ach 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 imagi= ne it would make some things a lot simpler...



On Wed, Sep 4, 2= 013 at 6:17 PM, Daniel B=FCnzli <daniel.buenzli@erratique.ch= > wrote:
Hello,

I have this type

=A0 type weight =3D [ `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 pro= vided by the compiler or is it subject to change ?

Best,

Daniel



--
Caml-list mailing list. =A0Subscription management and archives:
ht= tps://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

--001a11c36fe8065fe604e5995e46--