[Haskell-cafe] Why does this blow the stack?

Stefan O'Rear stefanor at cox.net
Fri Dec 21 19:06:20 EST 2007


On Fri, Dec 21, 2007 at 03:16:17PM -0800, David Benbennick wrote:
> 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.

Because they simply aren't the same.

Try applying your functions to undefined undefined.

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20071221/bbd26aed/attachment.bin


More information about the Haskell-Cafe mailing list