caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Simon Frost <sdfrost@ucsd.edu>
Cc: Caml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Equality of functional values
Date: Mon, 29 Jan 2007 22:59:47 +0100	[thread overview]
Message-ID: <1170107988.6952.13.camel@localhost.localdomain> (raw)
In-Reply-To: <1170104645.4564.304.camel@penguin.local>

Am Montag, den 29.01.2007, 13:04 -0800 schrieb Simon Frost:
> Dear Caml List,
> 
> I'm trying to use a software package written in ocaml (IBAL), however,
> it fails a test due to 'Fatal error: exception Invalid_argument("equal:
> functional value"). It seems that equality isn't defined for functional
> values in OCAML (although I'm not an expert), so I'm wondering what the
> workaround is. This apparently worked fine in ocaml 3.04, but not in
> later versions. I'm using ocaml 3.08.3, and I get this error message
> both on Linux (SUSE 9.1 Profession, x86_64) and Windows XP (x86). Any
> help would be greatly appreciated! I'd rather not have multiple versions
> of ocaml floating around...

As far as I remember there was a slight change for the equality around
3.07 or 3.08. Previous versions of O'Caml always tested for physical
equality first, and only if the two values are not the same they are
compared component by component. So if the two compared functions are
always the same, this equality test never failed. In current O'Caml,
such a physical test is not done. E.g. look at

# let f() = 42;;
val f : unit -> int = <fun>
# f = f;;
Exception: Invalid_argument "equal: functional value".
# f == f;;
- : bool = true

In old O'Caml versions "f = f" worked because the "f == f" test was
implicitly performed first. (This was changed because of an
incompatibility with conventional floating point semantics.)

If it is not possible to remove the functional parts from the compared
values entirely, there is an easy workaround: Wrap the functions into
objects. The equality for objects is well-defined: Objects are only
equal if they are the same.

The code looks now like:

# let obj_f = object method f() = 42 end;;
val obj_f : < f : unit -> int > = <obj>
# obj_f = obj_f;;
- : bool = true

In order to call the wrapped function:

# obj_f # f();;
- : int = 42

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------


  parent reply	other threads:[~2007-01-29 21:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-29 21:04 Simon Frost
2007-01-29 21:11 ` [Caml-list] " Tom
2007-01-29 21:23   ` Brian Hurt
2007-01-29 21:59 ` Gerd Stolpmann [this message]
2007-01-30  8:17   ` Christophe Raffalli
2007-01-30  8:45   ` David MENTRE
2007-01-30 13:24 ` Andrej Bauer
2007-01-30 13:55   ` skaller
2007-01-30 14:21     ` Brian Hurt
2007-01-30 15:21     ` Jeff Polakow
2007-01-30 15:49       ` Jacques Carette
2007-01-30 17:23         ` Chris King
2007-01-30 20:18           ` Tom
2007-01-30 20:30             ` Gerd Stolpmann
2007-01-30 20:41               ` Fernando Alegre
2007-01-30 21:01                 ` Christophe TROESTLER
2007-01-30 21:08                   ` Tom
2007-01-30 21:46                     ` Christophe TROESTLER
2007-01-30 22:05                       ` Fernando Alegre
2007-01-30 23:13                         ` skaller
2007-01-30 23:06     ` Andrej Bauer
2007-01-31  0:15       ` Jacques Carette
2007-01-31  7:03         ` Stefan Monnier
2007-01-31 12:54           ` [Caml-list] " Jacques Carette
2007-01-31  0:15       ` [Caml-list] " skaller

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=1170107988.6952.13.camel@localhost.localdomain \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=sdfrost@ucsd.edu \
    /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).