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 XAA21175; Wed, 25 Apr 2001 23:08:47 +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 XAA21246 for ; Wed, 25 Apr 2001 23:08:46 +0200 (MET DST) Received: from smtp2-cm.mail.eni.net (smtp2-cm.mail.eni.net [216.133.226.135]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f3PL8hP20171 for ; Wed, 25 Apr 2001 23:08:44 +0200 (MET DST) Received: from CHECKERATH (node-d8e9cca2.powerinter.net [216.233.204.162]) by smtp2-cm.mail.eni.net (8.9.3/8.9.3) with SMTP id OAA02055; Wed, 25 Apr 2001 14:08:33 -0700 Date: Wed, 25 Apr 2001 14:08:33 -0700 Message-Id: <200104252108.OAA02055@smtp2-cm.mail.eni.net> From: Chris Hecker To: caml-list@inria.fr Subject: [Caml-list] two unrelated questions Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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? 2. I'm confused as to when the compiler decides to inline and when it doesn't. None of the calls in the following program get inlined, regardless of the value of -inline in ocamlopt. It seems so trivial, and in fact, I wrote it to show a friend how the compiler is really good (and after running dumpobj on the bytecode and looking at the asm from ocamlopt, we went and saw with dismay how Pervasives.fst and .snd are builtins and not inlined functions): let a = 1,2 let myfst (a,b) = a let mysnd (a,b) = b let myfsti ((a,b):int*int) = a let mysndi ((a,b):int*int) = b let _ = myfst a + 1; 1 + mysnd a; myfsti a; mysndi a Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr