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 IAA24091; Thu, 26 Dec 2002 08:06:59 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA24280 for ; Thu, 26 Dec 2002 08:06:58 +0100 (MET) Received: from swordfish ([216.241.35.41]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gBQ76un20670 for ; Thu, 26 Dec 2002 08:06:57 +0100 (MET) Received: from matt by swordfish with local (Exim 3.35 #1 (Debian)) id 18RS6W-0000Uq-00 for ; Thu, 26 Dec 2002 00:06:52 -0700 Date: Thu, 26 Dec 2002 00:06:52 -0700 From: Matt Gushee To: caml-list@inria.fr Subject: [Caml-list] Guards vs. conditionals Message-ID: <20021226070651.GB1071@swordfish> Reply-To: Matt Gushee Mail-Followup-To: caml-list@inria.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.27i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, all-- 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. E.g.: let foo = function | i when i >= 500 -> true | i -> false does the same thing as let foo i = if i >= 500 then true else false And I wrote a pair of small programs, each of which invokes one of these functions on a random integer 100,000 times. The executables, whether byte-compiled or native, are almost exactly the same size and, according to a round of informal tests with GNU time, run at the same speed. This suggests that the compiled code is for all practical purposes the same. 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? -- Matt Gushee When a nation follows the Way, Englewood, Colorado, USA Horses bear manure through mgushee@havenrock.com its fields; http://www.havenrock.com/ When a nation ignores the Way, Horses bear soldiers through its streets. --Lao Tzu (Peter Merel, trans.) ------------------- 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