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 abstraction and (polymorphic) equality
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-06-29 (17:34)
From: William Lovas <wlovas@s...>
Subject: Re: [Caml-list] Type abstraction and (polymorphic) equality
On Wed, Jun 29, 2005 at 02:31:11AM +0200, Christophe TROESTLER wrote:
> Let me start with a little story that happened to me recently.
> [...]
> The problem was that the attached information (an additional field in
> a record) was a cyclic data structure.  From there on, all equality
> tests became deadly! (I would have preferred to have the exception
> Invalid_argument "equal: abstract value".)  What made matters worse is
> that the compiler could not help me to find the locations of such
> problems -- which can be hidden e.g. in List.mem.  Not a nice job to
> do...

A harrowing and tragic tale indeed!  While not really a solution to your
problems, you *can* obtain the "abstract value" exception behavior with a
little trick; Jacques Garrigue posted about it to the list a couple of
months ago:

I say it's no solution because (a) it doesn't keep you from having to write
your own equality predicate with a different name, and (b) the compiler
gives you no static warnings about invalid uses -- might as well program in
Scheme! ;)