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 MAA17463; Thu, 15 Jul 2004 12:18:29 +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 MAA16662 for ; Thu, 15 Jul 2004 12:18:28 +0200 (MET DST) Received: from annexia.force9.co.uk (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6FAIREV008812 for ; Thu, 15 Jul 2004 12:18:27 +0200 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1Bl3Jr-0002h9-00 for ; Thu, 15 Jul 2004 11:18:27 +0100 Date: Thu, 15 Jul 2004 11:18:26 +0100 Cc: caml-list@inria.fr Subject: Re: [Caml-list] assertions or exceptions? Message-ID: <20040715101826.GA10062@redhat.com> References: <7f8e92aa04071501035091cbe9@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7f8e92aa04071501035091cbe9@mail.gmail.com> User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones X-Miltered: at nez-perce with ID 40F659F3.000 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 extlib:01 reinventing:01 team's:01 ltd:98 ocaml:01 caml:01 caml:01 null:01 null:01 assertions:01 rec:01 underlying:01 eof:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Jul 15, 2004 at 11:03:24AM +0300, Radu Grigore wrote: > So, now a few questions: > 1. Is my impression that OCaml standard library is abusing > exceptions correct? There's always a conflict between raising a Not_found exception and returning an 'a option result. Example (from mod_caml). Should the function which returns the hostname field from the request_rec structure be prototyped as: Apache.Request.hostname : Apache.Request.t -> string # could throw Not_found if the C string is NULL. or: Apache.Request.hostname : Apache.Request.t -> string option # returns Some string, or None if the C string is NULL In fact, I chose the former (throwing Not_found exception) consistently throughout mod_caml. The reason is that returning 'a option forces you to deal with the 'None' case every time you use (eg). Apache.Request.hostname. But in many cases, the underlying C fields being NULL is an internal error for which we are not prepared, and the only sensible thing to do then is not to force people to deal with it locally, but to throw an exception which causes the whole script/program to fail. However in some cases the right thing to do would be to return 'a option, precisely *because* you require the programmer to deal with the error locally. > 2. Is it safe to assume that exceptions complicate functional > programs as much as they complicate imperative ones? Perhaps in theory, but in practice they work just fine. > 3. Is it possible to avoid using exceptions and read a text file > line-by-line until EOF? There are functions in ExtLib to do this, I think. If not then you should write a function like 'input_all_lines' or 'iter_over_lines f' once, put it into a small local library, and use it every time. No point reinventing wheels each time. Rich. -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investment 'There is a joke about American engineers and French engineers. The American team brings a prototype to the French team. The French team's response is: "Well, it works fine in practice; but how will it hold up in theory?"' ------------------- 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