The query quoted below, about heap usage in a 5-line Haskell program,
has remained unanswered for two weeks.
Can we conclude that reasoning about heap usage in lazy functional languages
is simply too difficult for mere mortals?
If even simple examples like this one are too hard for the experts that
read this mailing list, how are ordinary programmers supposed to reason
about heap usage in more complicated programs?
Yours sincerely,
Devil's advocate.
On 14-Sep-1998, Martin Stein <[EMAIL PROTECTED]> wrote:
> Hi,
>
> though I think there was written enough about this theme, I can't still
> understand the following problem (foldl' from the Prelude.hs):
>
> > seq1 x = (3-x):seq1 x
> > seq2 x = (3-x):seq2 1
> >
> > countOne xs = foldl' (\c x -> if x==1 then c+1 else c) 0 xs
> >
> > num1 n = countOne (take n (seq1 1))
> > num2 n = countOne (take n (seq2 1))
>
> num1 needs lots of heap space, num2 needs very few. Why?
> (I checked it using ghc and '+RTS -s')
>
> Martin Stein
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.