Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Are you sure the new "=" of 3.08 is good ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sébastien_Furic <sebastien.furic@t...>
Subject: Re: [Caml-list] Are you sure the new "=" of 3.08 is good ?
Christophe Raffalli wrote:
> 
> I spend one complete day to adapt Phox (my theorem prover) to 3.08
> because the new = does not check first physical equality. Hopefully, the 
> backtracking ocamldebugger let me pin point the many "=" which were 
> looping, otherwise I would have spend a month !!!
> 
> I was assuming two things about equal:
> - scan of block from left to right
> - a test on adress equality on pointer before follwing the pointer 
> (which is now wrong in 3.08).
> 
> Then in a data type with some structure starting with an identifier 
> filed like
> 
> type symbol = structh { id : int; ... },
> 
> if you have the property that two structures with the same id are always 
> physically equal, the old "=" would never scan the structure itself.

  IMHO it is often better to define your own equality predicates because 
"=" has another annoying property : it fails when comparing "external" 
objects and this failure happens only when comparison reaches those 
objects (note that the type system is perfectly happy, even in the 
presence of "external" objects). For instance, imagine one of the fields 
of a record you want to compare is a Big_int : your program will fail 
only if "=" can't decide for inequality before reaching those fields.

         Objective Caml version 3.08.1

# #load "nums.cma";;
# type test = { n: Num.num };;
type test = { n : Num.num; }
# { n = Num.num_of_string"10000000000000000000000000000000" } = { n = 
Num.num_of_string "200000000000000000000000000000000" };;
Exception: Invalid_argument "equal: abstract value".

  I discovered this behavior when I was developping libraries to handle 
DAGs for a symbolic manipulation program written in OCaml (using the Num 
library). All the preliminary tests of the libraries were OK (I only 
used "internal" objects) but the day I had to use them I had a great 
surprise : they were not as "generic" as I believed them to be.
   In conclusion, if you want your modules to be truly generic, never 
use "polymorphic" equality.

  Cheers,

  Sébastien.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners