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 RAA26260; Mon, 12 May 2003 17:24:47 +0200 (MET DST) 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 RAA25371 for ; Mon, 12 May 2003 17:24:46 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h4CFOEH02255; Mon, 12 May 2003 17:24:14 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA25320; Mon, 12 May 2003 17:24:14 +0200 (MET DST) Date: Mon, 12 May 2003 17:24:13 +0200 From: Xavier Leroy To: David Brown Cc: caml-list@inria.fr Subject: Re: [Caml-list] tree walking with... specular rec functions? what else? Message-ID: <20030512172413.A25042@pauillac.inria.fr> References: <200305121257.IAA29080@nerd-xing.mit.edu> <20030512133542.GA9977@roke.freak> <20030512150607.GA21915@opus.davidb.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20030512150607.GA21915@opus.davidb.org>; from caml-list@davidb.org on Mon, May 12, 2003 at 08:06:07AM -0700 X-Spam: no; 0.00; caml-list:01 compiler:01 implements:01 ocaml:01 caml:01 mutable:01 rec:01 imply:02 compile:02 tree:02 in-place:02 comparison:02 overhead:03 data:03 functions:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > Which means that lst = [] does not imply lst == []. > > > > In other words, one should use: > > > > if lst = [] then empty-code else full-code > > > > or pattern matching, as you said. > > Is it really not defined by Ocaml? Ocaml implements the empty list as > the integer value zero. Although (==) won't tell you if two cons-cells > have the same contents, it will tell you if they are the same. It happens to work in this case, but relies on features of the implementation. It's better to use "==" only between mutable data structures, where it has a well-defined meaning (two mutable structures are == iff an in-place modification to one of them affects the other one as well), and "=" otherwise. > So is there any implementation of a caml language where [] == [] isn't > always true, for any way that [] is generated? Both Caml Light and OCaml ensure [] == [], but again it's better not to rely on this fact. > The (=) has more overhead It doesn't: the OCaml compiler is clever enough to compile "lst = []" as a direct comparison against the integer value zero. - Xavier Leroy ------------------- 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