On Fri, Feb 27, 2004 at 02:29:50PM -0600, Kevin S. Millikin wrote: > I'm trying to figure out what I can rely on about physical equality. > I've checked the OCaml manual but can't seem to find what I want to > know. > > Presume > > # type t = V0 | V1 of int;; > type t = V0 | V1 of int > > # V0 == V0;; > - : bool = true > > V0's are the same. Is this guaranteed? Yes. > > # V1(0) == V1(0);; > - : bool = false > > V1's are different. Is this guaranteed? What do you mean by guaranteed? This is true, but it might become false: a) because the compiler optimize a common constant subexpression b) because the runtime might make these 2 values become the same (ie by hash-consing). c) there is a tricky issue regarding floating point compares for NaN. Read the source code or some previous posting on this (I never used NaN since I am not a numerical coder). As far as I know, neither a nor b is currently true (both in Ocaml3.07pl2 and in the latest CVS), but I could imagine that some later version of ocaml might do a or b (even if I believe this unlikely). The only reasonable implication about physical equality is a == b implies a = b (ie physical equality implies structural equality) Why would you want a guarantee that V1 0 is not physically equal to V1 0? I tend to think that making such an hypothesis is dangerous and wrong, even if the current implementation demonstrate it. Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet aliases: basiletunesorg = bstarynknerimnet 8, rue de la Faïencerie, 92340 Bourg La Reine, France ------------------- 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