Version franēaise
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Physical compare
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe Filliatre <filliatr@l...>
Subject: Re: [Caml-list] Physical compare


Tom Hawkins writes:
 > Is their a version of "compare" that is based on physical equality?  If 
 > not, how can I define one?  I tried:
 > let compareq a b = if a == b then 0 else if a > b then 1 else (-1)
 > But unfortunately, (>) is a structural comparison.
 > I need to make a Map where the keys are distinguished by the physical 
 > instance.

Others already  gave the right answer  i.e. that you need  to tag your
values with unique integers to do that.

Just to  mention it, I wrote  a little hash-consing  library that does
precisely this, together with specialized  versions of Set and Map for
these tagged values  (based on Patricia trees). There  is even a short
article describing the technique. All is available on this page:

Hope this helps,
Jean-Christophe Filliātre (