From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA28079 for caml-redistribution; Mon, 15 Mar 1999 14:35:39 +0100 (MET) 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 KAA14300 for ; Mon, 15 Mar 1999 10:07:04 +0100 (MET) Received: from p-voyageur.issy.cnet.fr (p-voyageur.issy.cnet.fr [139.100.0.39]) by nez-perce.inria.fr (8.8.7/8.8.7) with SMTP id KAA28063 for ; Mon, 15 Mar 1999 10:07:02 +0100 (MET) Received: from l-mhs1.lannion.cnet.fr ([161.104.1.59]) by p-voyageur.issy.cnet.fr with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2232.9) id GGMHPXM1; Mon, 15 Mar 1999 10:03:02 +0100 Received: from lsun565.lannion.cnet.fr ([161.104.10.182]) by l-mhs1.lannion.cnet.fr with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2232.9) id ZNBGS59K; Mon, 15 Mar 1999 10:11:37 +0100 Received: from lsun565.cnet by lsun565.lannion.cnet.fr (SMI-8.6/SMI-SVR4) id KAA29053; Mon, 15 Mar 1999 10:06:45 +0100 Date: Mon, 15 Mar 1999 10:06:45 +0100 Message-Id: <199903150906.KAA29053@lsun565.lannion.cnet.fr> From: Jean-Francois Monin MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Alexey Nogin Cc: Jean-Francois Monin , caml-list@inria.fr Subject: Re: List.filter in Ocaml 2.02 In-Reply-To: <36E95F00.129D35DB@CS.Cornell.EDU> References: <19990305114112.34610@pauillac.inria.fr> <36E854D1.E52CD73B@CS.Cornell.EDU> <199903121011.LAA27611@lsun565.lannion.cnet.fr> <36E95F00.129D35DB@CS.Cornell.EDU> X-Mailer: VM 6.37 under Emacs 20.2.1 Sender: weis Alexey Nogin wrote : > > exception Identity > > > > let share f x = try f x with Identity -> x > > > > let filter f l = > > let rec fil = function > > | [] -> raise Identity > > | h :: t -> > > if f h then h :: fil t else share fil t in > > share fil l > [...] > 2) Even if the list is not changed, you first allocate the space and put > its copy there, then raise an exception and return the old value. That > means that you first waste time in memory allocation and then you waste > it in garbage collection. I don't agree, because this construction > > if f h then h :: fil t else share fil t in ^^ should never be evaluated when Identity is raised in the "fil t" occurring just after. At least, if you replace "h :: fil t" with "h $$ fil t", where let ($$) x l = x :: l you get the expected behavior (for mem alloc concerns). It would be very surprising that the above program behaves not the same. -- Jean-Francois