Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: brogoff <brogoff@s...>
Subject: Re: [Caml-list] looping recursion
On Tue, 27 Jul 2004 briand@aracnet.com wrote:
> >>>>> "Brian" == Brian Hurt <bhurt@spnz.org> writes:
> it really is.
> although I'd actually like it to be an array.
> it's the classic situation, read whole file - iterate on elements.
> easy to do in a list since I don't need to know the size.
>
> some minor tweaks and I can include the size in a data file and just
> fill an array directly.
>
> however, my larger point is the fact that the "standard" map blows up
> like that.  as a long time scheme user I just find that plain weird.
> Now Everybody else seems to think I'm weird because I think that's
> weird ;-)
>
>   Brian> Very long lists are a sign that you're using the wrong data
>   Brian> structure.
>
> I'm not sure I understand that.

I've heard the argument plenty of times, and I'm familiar with all of the
common data structures (and the uncommon ones in Okasaki's book), and I don't
buy that argument either.

It's a limitation of the current OCaml list library functions and the current
implementation of OCaml. You can easily fix it yourself by writing mapand
friends  to be tail recursive in the straightforward way (suboptimal efficiency,
but better than failing)  or the non-obvious way using Obj to make the
equivalent of set-cdr! (what ExtLib does) or wait until the implementors
decide to fix this by adding a language feature and reimplementing List.
Don't hold your breath for that last option.

> Part of the problem is that powerful computers make for lazy
> programmers :-) It's just so easy to read the 10^6 elements into a
> list and then just keep map'ing them to the final value when it only
> takes seconds to do :-) If it took 2 minutes I'd be more inclined to
> think about the problem.

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.

-- Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners