caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Physical compare
Date: Wed, 23 Nov 2005 19:38:59 +0000	[thread overview]
Message-ID: <200511231938.59745.jon@ffconsultancy.com> (raw)
In-Reply-To: <4384C0E3.5030300@confluent.org>

On Wednesday 23 November 2005 19:20, Tom Hawkins wrote:
> Is their a version of "compare" that is based on physical equality?  If
> not, how can I define one?

Due to the use of a copying collector you cannot define one because the 
pointers that make up references can change value, i.e. a < b might not 
remain true for very long.

> I need to make a Map where the keys are distinguished by the physical
> instance.

Tag every key with a unique integer using something like this:

module Tag : sig
  type 'a t
  val make : 'a -> 'a t
  val compare : 'a t -> 'a t -> int
end = struct
  type 'a t = int * 'a
  let i = ref 0
  let make x =
    incr i;
    !i, x
  let compare (a, _) (b, _) = compare a b
end;;

Then use the Tag.compare function to perform physical comparison with a total 
ordering.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists


  reply	other threads:[~2005-11-23 19:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-23 19:20 Tom Hawkins
2005-11-23 19:38 ` Jon Harrop [this message]
2005-11-23 19:49 ` [Caml-list] " Nicolas Cannasse
2005-11-24 15:33 ` Jean-Christophe Filliatre

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=200511231938.59745.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --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).