From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 23A01BC0A for ; Mon, 29 Jan 2007 22:59:54 +0100 (CET) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.183]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0TLxrPA010263 for ; Mon, 29 Jan 2007 22:59:53 +0100 Received: from [84.59.109.220] (helo=gate.lan.gerd-stolpmann.de) by mrelayeu.kundenserver.de (node=mrelayeu2) with ESMTP (Nemesis), id 0MKwtQ-1HBeXX0dnO-0005lf; Mon, 29 Jan 2007 22:59:51 +0100 Received: from flakew.lan.gerd-stolpmann.de (fw.lan.gerd-stolpmann.de [192.168.1.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id A2E47C05F; Mon, 29 Jan 2007 22:59:48 +0100 (CET) Subject: Re: [Caml-list] Equality of functional values From: Gerd Stolpmann To: Simon Frost Cc: Caml List In-Reply-To: <1170104645.4564.304.camel@penguin.local> References: <1170104645.4564.304.camel@penguin.local> Content-Type: text/plain Date: Mon, 29 Jan 2007 22:59:47 +0100 Message-Id: <1170107988.6952.13.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de login:a6865a839c0178d9aa0ce41878507ea2 X-Provags-ID2: V01U2FsdGVkX19ABmgI4oL/Ut6/Ljyz05+S5MTrZ51TfyOV8xEou0Hy0aQmLu9EYwbFIZf6sIk7KxAm5QzS3otJOmHKpxciuxMTCe+wUMxF3LS3xH+ehr53QGr1tKit6Bf+ X-Miltered: at discorde with ID 45BE6E59.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; gerd:01 stolpmann:01 ocaml:01 ocaml:01 o'caml:01 o'caml:01 val:01 bool:01 implicitly:01 semantics:01 val:01 bool:01 gerd:01 stolpmann:01 viktoriastr:01 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 = # 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_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 ------------------------------------------------------------