Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] looping recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-28 (21:22)
From: brogoff <brogoff@s...>
Subject: Re: [Caml-list] looping recursion
On Wed, 28 Jul 2004, Jon Harrop wrote:
> On Wednesday 28 July 2004 17:38, brogoff wrote:
> > > brogoff wrote:
> > > > Sometimes lists are best. If lists are OK for 100, 1_000, or 10_000
> > > > items, why not 100_000 or 1_000_000? Map and friends shouldn't blow
> > > > stack.
> Creating an int list with 1,000,000 elements and applying using
> ocamlopt works fine here, and took a meagre 3.6 secs.
> If you must use bytecode for this then just increase the stack size limit, for
> example to 8Mb:
> export OCAMLRUNPARAM='l=8M'
> Then it runs fine, in 10.7 secs here. Wow, that's quite fast... :-)

I'm going to guess that you don't have much OCaml code running at a customer
site. Yes, I'm aware that stack size can be reset. Oh joy. I guess we don't
need tail call elimination at all then?

> > Well, I'm still on the caml-list, so of course it isn't *that* bad. Also,
> > as I said, if you need a tail recursive map over built in lists, you have
> > at least two options. Unfortunately, my preference is to use Obj, which IMO
> > points to a deficiency in the core language.
> No! That points to a severe deficiency in your programming style. OCaml has
> been developed and used by a great many very clever people, and me. If you're
> doing things like that then you should immediately stop and think what you
> might be doing wrong.

I guess all of the authors of ExtLib, who, last time I checked, used a set_cdr
approach, are also tyros compared to you?

> Perhaps you picked the bad style up at a Seattle OCaml user group meeting?

Very classy. :-(

> What's wrong with List.rev_map, List.rev (List.rev_map ...), increasing the
> size of the VM's stack, using native code or even writing your own,
> tail-recursive map?

I'm pretty damned well aware that I can reverse a rev mapped list. Does it occur
to you that that is not efficient? Have you tried comparing the run times of
this versus set_cdr version? Where were you when the "tail recursion modulo
cons" discussion came up? Do you understand that optimization? Here's a pointer
for you

By my measurements, even for small lists, the set_cdr version was as fast (a
little faster even) than, and it had the nice property of not failing
with huge lists.

-- Brian

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: