Fergus Henderson [mailto:[EMAIL PROTECTED]] writes:
>
> 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?
>
No, I think that's pushing it too far, at least in this case.
It isn't clear from the report how to reproduce the behaviour,
most of my attempts to do so came out with near identical
behaviour for num1 and num2 (this is with ghc-2.10 and ghc-3.03).
That's not to say that there isn't a problem lurking here
somewhere. One plausible reason for why seemingly identical
functions could behave wildly differently even when functions
such as foldl' are used, is that < 4.00 versions of ghc doesn't
do polymorphic seq'ing. Hence, if you define functions that
are overloaded (such as num1 and num2) you're likely to lose,
even more so if the ghc version used doesn't have specialiser
around.
Without knowing what version of ghc that was used (and the exact
test program), it's hard to pinpoint the cause.
--Sigbjorn
>
> 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
>