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
type of ==
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe DEHLINGER <christophe.dehlinger@i...>
Subject: Re: [Caml-list] type of == - Bayesian Filter detected spam
Jon Harrop wrote:

>Assuming this is for an OCaml-only program, it sounds as though the "other" 
>possible types 'a and 'b should be put into a single variant type. Then you 
>can use "'a -> 'a -> bool" with "'a = your variant type". Does that make any 
>sense? :-)
Alas, this does not work for me. This is for an OCaml-only module, in 
which the "other" types are all instances of one polymorphic mutable 
record type, but the number or exact values of these instances are not 
known within the module and may be pretty much anything.

Fortunately, I have an easy workaround in my case, but it can't really 
be generalized. The polymorphic record type contains a "node" field 
(which is a non-polymorphic mutable record). I know that two records 
cannot share the same physical node, so I basically use the node as a 
unique identifier for the records:

type ('a, 'b) my_record_type = { ... ; node : node_type ; ... }
let my_eq : ('a, 'b) my_record_type -> ('c,'d) my_record_type -> bool =
  fun x y -> x.node == y.node

Obviously, this method only works if you have such a unique identifier 
for every object you have to compare. If this node field hadn't been 
there, I would have been stuck with either cheating with the Obj module, 
or artificially adding a unique identifier to each record (like an int 
or a unit ref). The latter would have been quite frustrating, because it 
would cost execution time + memory + readability only to get around the 
arguably artificial typing limitation of == .



Ce message (et toutes ses pièces jointes éventuelles) est confidentiel et établi à l'intention exclusive de ses destinataires. Toute utilisation de ce message non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'IFP décline toute responsabilité au titre de ce message.

This message and any attachments (the message) are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. IFP should not be liable for this message.

Visitez notre site Web / Visit our web site :