From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA04789; Fri, 16 Jan 2004 01:45:16 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA26288 for ; Fri, 16 Jan 2004 01:45:14 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i0G0gb524311 for ; Fri, 16 Jan 2004 01:42:39 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id JAA04862; Fri, 16 Jan 2004 09:42:28 +0900 (JST) To: skaller@tpg.com.au Cc: caml-list@inria.fr Subject: Re: [Caml-list] Stupid question In-Reply-To: <1074139041.7527.2.camel@localhost.localdomain> References: <1074139041.7527.2.camel@localhost.localdomain> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20040116094357V.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 16 Jan 2004 09:43:57 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 stupid:01 jacques:01 tpg:99 2004:99 poking:01 inequality:01 optimised:01 non-constant:01 optimised:01 jacques:01 compiler:01 compiler:01 bool:01 bool:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: skaller > On Thu, 2004-01-15 at 11:03, Brian Hurt wrote: > > I was poking around in the produced assembly code of some ocaml code of > > mine, and I noticed something. The construct: > > if (x < m) <> (y < m) then > > ... > > > > when the compiler knows that x, y, and m are all ints, it calls an > > external C routine to compare the two booleans. But the construct: > > > > if (x < m) != (y < m) then > > ... > > > > does not. Now, this isn't a big deal- I just replaced <> with != and no > > problem. But I was kind of interested in why the compiler didn't catch > > and optimize this. Is there some sort of subtle semantic difference I'm > > too dense to see? > > Well, <> is a polymorphic value comparison. > Whereas != is a physical inequality comparison. Yes indeed. But the compiler is clever enough to use specific comparison functions when the type is known to be int or float. Since bool looks like a subset of int, one might expect it to be optimised also. However, bool is just a normal sum type, and since some sum types have non-constant constructors, in general sum types require a recursive comparison operation. For types where constructors are constant, this might be optimised... Jacques Garrigue ------------------- 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