caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pascal Cuoq <Pascal.Cuoq@cea.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Physical counterpart to Pervasives.compare?
Date: Wed, 29 Jul 2009 09:04:53 +0200	[thread overview]
Message-ID: <60DA2C46-E67F-44BF-9ECC-625461BF10B5@cea.fr> (raw)
In-Reply-To: <20090729030710.BB3C6BC5C@yquem.inria.fr>

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

Edgar Friendly wrote:
>
> Elnatan Reisner wrote:
>> Is there something that can complete this analogy:
>> (=) is to (==) as Pervasives.compare is to ___?
>>
>> That is, is there a polymorphic total ordering with respect to  
>> *physical*
>> entities, rather than to their structure?
>>
> No, but it'd be pretty trivial to implement through the C interface.

No, it would not be trivial to implement, because you would not want the
order of two values to change each time one is moved from the minor heap
to the major heap or when the major heap is compacted.
The article linked below is about this kind of topic (among other
things), in the context of Haskell.

http://research.microsoft.com/en-us/um/people/simonpj/papers/weak.htm

The simple solution is to number at creation the objects that you want  
to
physically compare, using an additional field.

> If you had to stay in the OCaml realm, you might be able to do [let
> phys_comp (x:'a) (y:'a) = (Obj.magic x) - (Obj.magic y)], but it  
> depends
> on the exact implementation of (-) on your architecture, as it may
> produce a value that's not an OCaml int when given non-ints as input.

As an additional general remark, it is a bad idea to use "x - y"
as an implementation of "compare x y" because of overflows.

Pascal


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

       reply	other threads:[~2009-07-29  7:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090729030710.BB3C6BC5C@yquem.inria.fr>
2009-07-29  7:04 ` Pascal Cuoq [this message]
2009-08-24  7:01   ` Jean-Christophe Filliâtre
     [not found] <20090824100004.6DBBDBBAF@yquem.inria.fr>
2009-08-24 12:30 ` Pascal Cuoq
2009-08-25 18:03   ` Christophe Raffalli
2009-08-26 10:25     ` Damien Doligez
2009-07-29  1:25 Elnatan Reisner
2009-07-29  3:06 ` [Caml-list] " Edgar Friendly
2009-07-29  3:58   ` Edgar Friendly
2009-07-29  6:13 ` Alain Frisch

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=60DA2C46-E67F-44BF-9ECC-625461BF10B5@cea.fr \
    --to=pascal.cuoq@cea.fr \
    --cc=caml-list@yquem.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).