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=1.1 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL 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 06071BC0B for ; Tue, 30 Jan 2007 21:18:38 +0100 (CET) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.169]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0UKIbWG011694 for ; Tue, 30 Jan 2007 21:18:37 +0100 Received: by ug-out-1314.google.com with SMTP id q2so1806347uge for ; Tue, 30 Jan 2007 12:18:36 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=i5jKN1Y4+S0eCkjPAjZy7rEH013dKEe9IIQzDkXk4xVpFEJU+txLn1uPrKstmghS2+ZFEWm+1xfcOTslY+beZU9hh5qi740qmZ0iIfgaYlvmIPNLAMHXrWf34wDZjx9Uhmgbf1sRGXjGu0o3maUeu+9Vjl0DD4jDCt/pZI/1XGc= Received: by 10.82.165.1 with SMTP id n1mr4504143bue.1170188316370; Tue, 30 Jan 2007 12:18:36 -0800 (PST) Received: by 10.82.175.13 with HTTP; Tue, 30 Jan 2007 12:18:36 -0800 (PST) Message-ID: Date: Tue, 30 Jan 2007 21:18:36 +0100 From: Tom To: "Chris King" Subject: Re: [Caml-list] Equality of functional values Cc: "Jacques Carette" , caml-list@yquem.inria.fr In-Reply-To: <875c7e070701300923r362b1032sac4125fd2879f8ae@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_156089_31548115.1170188316211" References: <45BF691B.8090506@mcmaster.ca> <875c7e070701300923r362b1032sac4125fd2879f8ae@mail.gmail.com> X-j-chkmail-Score: MSGID : 45BFA81D.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45BFA81D.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 val:01 bool:01 bool:01 wishlist:01 ocaml:01 val:01 wishlist:01 W8:98 W8:98 W16:98 equality:01 equality:01 recursively:01 recursively:01 X-Attachments: cset="UTF-8" cset="UTF-8" ------=_Part_156089_31548115.1170188316211 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I guess the "correct" way to do = equality would be to check for tag ( Obj.tag (Obj.repr x)), and if it isn't float (or float array) then == equality would be performed first. The problem is that this would have to be implemented by the OCaml developers, as the naive implementation: let equal x y = if Obj.tag (Obj.repr x) = Obj.double_tag then x = y else if x == y then true else x = y doesn't work, as it should be called recursively (comparing two lists of functions will fail, because the functions would be compared by =, not by equal). Actually, the implementation could be improved further, as it could actually return true on examples such as # let f x y = x + y;; val f : int -> int -> int = # f == f;; - : bool = true # (f 1) = (f 1);; - : bool = true because the parameters, passed to a closure, could be compared, too... Anyhow, this can be added to the wishlist :) - Tom ------=_Part_156089_31548115.1170188316211 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline I guess the "correct" way to do = equality would be to check for tag (Obj.tag (Obj.repr x)), and if it isn't float (or float array) then == equality would be performed first. The problem is that this would have to be implemented by the OCaml developers, as the naive implementation:

let equal x y =
         if Obj.tag (Obj.repr x) = Obj.double_tag then x = y
         else
                 if x == y then true else x = y

doesn't work, as it should be called recursively (comparing two lists of functions will fail, because the functions would be compared by =, not by equal).

Actually, the implementation could be improved further, as it could actually return true on examples such as

# let f x y = x + y;;
val f : int -> int -> int = <fun>
# f == f;;
- : bool = true
# (f 1) = (f 1);;
- : bool = true

because the parameters, passed to a closure, could be compared, too...

Anyhow, this can be added to the wishlist :)

- Tom
------=_Part_156089_31548115.1170188316211--