Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] assertions or exceptions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Radu Grigore <radugrigore@g...>
Subject: Re: [Caml-list] assertions or exceptions?
On Thu, 15 Jul 2004 15:33:05 +0100, Jon Harrop
<postmaster@jdh30.plus.com> 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