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

Luke Palmer lrpalmer at gmail.com
Sat Dec 22 03:15:41 EST 2007

```On Dec 22, 2007 12:06 AM, Stefan O'Rear <stefanor at cox.net> > > 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.

This took a little work for me to see.  Here it is for the interested:

Prelude> let edi :: Integer -> Integer -> [Integer]; edi x d = x : edi (x+d) d
Prelude> let edi' :: Integer -> Integer -> [Integer]; edi' x d = let s
= x + d in x : (seq s \$ edi s d)
Prelude> _:_:_ <- return \$ edi undefined undefined
Prelude> _:_:_ <- return \$ edi' undefined undefined
*** Exception: Prelude.undefined

Luke
```