[Haskell-cafe] Why does this blow the stack?
David Benbennick
dbenbenn at gmail.com
Fri Dec 21 18:16:17 EST 2007
On Dec 21, 2007 2:30 PM, Don Stewart <dons at galois.com> wrote:
> dbenbenn:
> > Thanks for fixing this. But doesn't GHC have strictness analysis?
>
> Sure does!
>
> The problem here was an explicit recusive loop though,
> with just not enough for the strictness analyser to get going.
The explicit loop you're talking about is:
enumDeltaInteger :: Integer -> Integer -> [Integer]
enumDeltaInteger x d = x : enumDeltaInteger (x+d) d
That code isn't very complicated, and I would hope to be able to write
code like that in my own programs without having to worry about
strictness. Given that the compiler even has an explicit signature,
why can't it transform that code to
enumDeltaInteger x d = let s = x + d in x : (seq s $ enumDeltaInteger s d)
since it knows that (Integer+Integer) is strict? Of course, improving
the strictness analysis is harder, but it pays off more, too.
More information about the Haskell-Cafe
mailing list