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 KAA08133; Fri, 11 Jan 2002 10:23:42 +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 KAA08383 for ; Fri, 11 Jan 2002 10:23:41 +0100 (MET) 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 g0B9NZP02194; Fri, 11 Jan 2002 10:23:35 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA08325; Fri, 11 Jan 2002 10:23:34 +0100 (MET) Date: Fri, 11 Jan 2002 10:23:34 +0100 From: Xavier Leroy To: John Prevost Cc: caml-list@inria.fr, romildo@uber.com.br Subject: Re: [Caml-list] Function definition with multiple patterns in multiple equations Message-ID: <20020111102334.A7963@pauillac.inria.fr> References: <20020108110836.A9147@darling.home.br> <20020108082639.A87628@libcom.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20020108082639.A87628@libcom.com>; from jprevost@libcom.com on Tue, Jan 08, 2002 at 08:26:39AM -0500 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Anyway, the quick-n-dirty method of doing multiple patterns like > your example is to write: > > let f a b = match (a,b) with > | (0, 0) -> 1 > | (_, _) -> 0 > > But, this may very well have the overhead of actually building a > pair. Not in Objective Caml. There's a special optimization in both the bytecode and native-code compilers to avoid the construction of the pair in this case. You can also decompose it into something like: > > let f = function > | 0 -> (function > | 0 -> 1 > | _ -> 0) > | _ -> 0 > > Which is, yes, rather unattractive for such a small example. That should be: let f = function | 0 -> (function | 0 -> 1 | _ -> 0) | _ -> (function _ -> 0) And it would be less efficient due to the extra function invocation involved. (Assuming f is generally applied to two arguments; if you do a lot of partial applications of f, the latter might be slightly more efficient.) - Xavier Leroy ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr