caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi VANICAT <vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] On the equality of functional values
Date: Sun, 27 Oct 2002 19:02:16 +0100	[thread overview]
Message-ID: <87lm4jdal3.dlv@wanadoo.fr> (raw)
In-Reply-To: <3DBBF3F3.8080600@baretta.com> (Alessandro Baretta's message of "Sun, 27 Oct 2002 15:10:59 +0100")

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


      parent reply	other threads:[~2002-10-27 18:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-27 14:10 Alessandro Baretta
2002-10-27 15:34 ` David Brown
2002-10-27 17:58 ` David Monniaux
2002-10-28  6:15   ` Alessandro Baretta
2002-10-28  8:34     ` jeanmarc.eber
2002-10-29 10:32     ` Pierre Weis
2002-10-27 18:02 ` Remi VANICAT [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lm4jdal3.dlv@wanadoo.fr \
    --to=vanicat@labri.u-bordeaux.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).