[Haskell-cafe] Flattening tail recursion?

GoldPython goldpython at gmail.com
Fri Dec 10 14:38:22 EST 2004


Duh, just read above a bit closer. Sorry for the clutter...


On Fri, 10 Dec 2004 13:53:38 -0500, GoldPython <goldpython at gmail.com> wrote:
> Thanks to all for the good info. I see what tail recursion is now.
> Robert's example above leads me to a couple questions:
> 
> I had actually written my countlines like Robert's before the other
> one I mailed in and mine overflowed the stack just like his. According
> to people's responses, this one really is tail recursive, isn't it? If
> so why does it not get flattened out?
> 
> 
> 
> countlines = aux 0
>  where aux x [] = x
>        aux x (_:ls) = aux (x+1) ls
> 
> countlines' = aux 0
>  where aux x [] = x
>        aux x (_:ls)
>            | x `seq` False = undefined
>            | otherwise     =  aux (x+1) ls
> 
> Lastly, I've not seen the seq operator shown here in Robert's
> countlines' before. What does it do?
>


More information about the Haskell-Cafe mailing list