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 DAA23551; Thu, 26 Apr 2001 03:13:33 +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 DAA23317 for ; Thu, 26 Apr 2001 03:13:32 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f3Q1DUP25057 for ; Thu, 26 Apr 2001 03:13:30 +0200 (MET DST) Received: from localhost (mikan.kurims.kyoto-u.ac.jp [130.54.16.202]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id KAA10811; Thu, 26 Apr 2001 10:13:21 +0900 (JST) To: checker@d6.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] two unrelated questions In-Reply-To: <200104252108.OAA02055@smtp2-cm.mail.eni.net> References: <200104252108.OAA02055@smtp2-cm.mail.eni.net> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010426101322D.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 26 Apr 2001 10:13:22 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Chris Hecker > 1. What is the right "functional pattern" for early-outing on success > while using an iter/map/fold type function? Say I'm using iter to > search for something in an opaque datastructure. Should I throw > an exception to get out, or is that bad style? I guess this > question only makes sense for iter, since map/fold produce results > that you theoretically want to preserve. So, the question is > really, given an iter-style interface to a datastructure (one that > takes an ('a -> unit)), how do you tell it to stop iterating? I > guess if the function was ('a -> bool) you could do it that way, > but most iters aren't ((List|Array|Hashtbl).iter, for example). > Is throwing an exception the best bet? How to escape with an exception is described in section 8 of the caml-light tutorial: http://caml.inria.fr/tutorial/index.html. So I suppose this can be described as good style. Particularly you can see in section 8.3 how to escape with a return value, which is a natural thing to do in a search algorithm, and is a bit nicer than using a reference cell. Cheers, Jacques Garrigue ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr