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 KAA22971; Sat, 14 Jul 2001 10:31:13 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA22975 for ; Sat, 14 Jul 2001 10:31:12 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6E8VAf11512; Sat, 14 Jul 2001 10:31:10 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id KAA26205; Sat, 14 Jul 2001 10:31:10 +0200 Date: Sat, 14 Jul 2001 10:31:10 +0200 From: Daniel de Rauglaudre To: "Alexander V. Voinov" Cc: "caml-list@inria.fr" Subject: Re: [Caml-list] Generation of streams is slow Message-ID: <20010714103110.A26003@verdot.inria.fr> References: <3B4F70D7.82E58A91@quasar.ipa.nw.ru> <20010714042701.A24266@verdot.inria.fr> <3B4FB39D.10D1F6D5@quasar.ipa.nw.ru> <20010714060417.A25766@verdot.inria.fr> <3B4FC748.F9E14008@quasar.ipa.nw.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0us In-Reply-To: <3B4FC748.F9E14008@quasar.ipa.nw.ru>; from avv@quasar.ipa.nw.ru on Fri, Jul 13, 2001 at 09:15:04PM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Fri, Jul 13, 2001 at 09:15:04PM -0700, Alexander V. Voinov wrote: > I see, Prolog habits are hard to leave. But this solution doesn't look > as "natural" as mine It is not, indeed, but if you have long lists, it is the normal approach. You would have the same problem with List.map which is not tail recursive either. > and requires additional time to reverse the result. Exact, but List.rev is tail recursive. All non tail recursive functions can be rewritten in a recursive way by adding the accumulator value as parameter. If if is a list, it is reversed and you have to reverse it. A way to avoid that (I mean creation of a reversed list and reversion) is to use mutable types, what the list type is not. > I try to acquire hints for the everyday use, of lists and other > abstract sequences in this case. Not just a particular problem to solve. In the List module, some functions are tail recursive, other not. It has been planed for non too big lists. If you have big lists, you have to be careful of that. You may have to write your own functions in some cases. Also be careful of code enclosed by try..with: it prevents tail recursion. A "try a with b -> c" enclosing a recursive call in "a" must be rewritten as: match (try Some a with b -> None) with Some x -> a | None -> c It is heavy code, but mandatory: I often use it. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr