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 KAA25475; Thu, 2 Jan 2003 10:54:24 +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 KAA25373 for ; Thu, 2 Jan 2003 10:54:23 +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 h029sNH10401 for ; Thu, 2 Jan 2003 10:54:23 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA24758 for caml-list@inria.fr; Thu, 2 Jan 2003 10:54:22 +0100 (MET) Date: Thu, 2 Jan 2003 10:54:22 +0100 From: Xavier Leroy To: caml-list@inria.fr Subject: Re: [Caml-list] Guards vs. conditionals Message-ID: <20030102105422.I24166@pauillac.inria.fr> References: <20021226070651.GB1071@swordfish> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20021226070651.GB1071@swordfish>; from mgushee@havenrock.com on Thu, Dec 26, 2002 at 12:06:52AM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I'm just curious about something. I've been noticing that in many cases > (if not always) a pattern match with guard expressions in OCaml is > equivalent to a conditional statement. Not always strictly equivalent. Consider match x with hd::tl when hd <> 0 -> | _ -> Without "when", you'd need to duplicate : match x with hd::tl -> if hd <> 0 then else | _ -> > So, my question is, is there any objective reason to prefer the > pattern-match version over the conditional, or vice versa? Or is it just > a matter of coding style? It's just a question of style. Personally, I'd recommend using "when" in cases where "real" pattern-matching is involved, as in the example above, and cascades of "if...then...else..." in cases where it doesn't cause duplication of code. But you can opt for a different style. - 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