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 RAA31844; Thu, 15 Jul 2004 17:05:49 +0200 (MET DST) 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 RAA32110 for ; Thu, 15 Jul 2004 17:05:48 +0200 (MET DST) Received: from mproxy.gmail.com (mproxy.gmail.com [216.239.56.241]) by nez-perce.inria.fr (8.12.10/8.12.10) with SMTP id i6FF5kEV010636 for ; Thu, 15 Jul 2004 17:05:47 +0200 Received: by mproxy.gmail.com with SMTP id w29so1211318cwb for ; Thu, 15 Jul 2004 08:05:39 -0700 (PDT) Received: by 10.11.118.39 with SMTP id q39mr62010cwc; Thu, 15 Jul 2004 08:05:36 -0700 (PDT) Message-ID: <7f8e92aa04071508051155f4ec@mail.gmail.com> Date: Thu, 15 Jul 2004 18:05:36 +0300 From: Radu Grigore To: caml-list@inria.fr Subject: Re: [Caml-list] assertions or exceptions? In-Reply-To: <200407151533.05850.postmaster@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <7f8e92aa04071501035091cbe9@mail.gmail.com> <200407151335.23097.postmaster@jdh30.plus.com> <7f8e92aa04071506453ef7345d@mail.gmail.com> <200407151533.05850.postmaster@jdh30.plus.com> X-Miltered: at nez-perce with ID 40F69D4A.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 postmaster:99 generic:01 implemented:01 generic:01 imposing:01 insulting:01 inefficient:01 int:01 int:01 assertions:01 behaviour:01 exception:02 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 15 Jul 2004 15:33:05 +0100, Jon Harrop wrote: > > Differences between these are: > > Mine is generic over all data structures which provide a fold function or can > have a fold function implemented over them. Yours only works on the humble > list. ;-) That's why I said "all I can do is.." and not "here is a better solution" :) Yours is clearly better. I think that one of the important characteristics of your code is that it uses exceptions in a localized way that makes it hard to introduce bugs: Zero is used only in two lines. For this reason I think it would have been better if you could have declared the exception Zero in the scope of the function prod. I wouldn't want the fold function to catch it! Another characteristic is the one you already pointed out to: you can alter the behaviour of a higher order function in a way that simple functions (ie. without exceptions) do not provide. This is why I can't think of any generic solution to your puzzle that doesn't use exceptions (without imposing additional restrictions on the fold function, such as using int option instead of int -- which is inefficient and ugly). This is the kind of patterns I was looking for when I wrote the original message. Thanks again. It seems however that my style that was meant to be provoking by slightly playing the devil's advocate was considered insulting by some members of the list. I apologize. regards, radu ------------------- 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