Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] On the equality of functional values
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] On the equality of functional values
Alessandro Baretta <alex@baretta.com> writes:

> I have been experimenting with equal signs, and I noticed that the
> equality operator (=) behaves in a strange way with respect to
> functional values.
>
>          Objective Caml version 3.06
>
> # (=) = (=) ;;
> Exception: Invalid_argument "equal: functional value".
> # let x = (=) in x = x ;;
> - : bool = true
>
> The first line seems to imply that no comparisons are possible between
> functional values. However, the second line I typed does not raise the
> same exception. This seems to imply that comparisons are allowed
> between functional values, too.
>
> Now, which of two hypotheses is correct?

The first one. But the fact is that before making a structural
equality test, ocaml try to see if both argument have the same address,
and then return true, so equality may work if both argument are
exactly the same closure. (then, there is a subtlety : the = function
is a c function, not a caml one. So when one refer to (=), caml build
a new fresh closure, that is different from any other closure).
(and there is another subtlety, making executable generated by ocaml
and by ocamlopt having some subtle difference in this case).

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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