[Haskell-cafe] Flattening tail recursion?

GoldPython goldpython at gmail.com
Fri Dec 10 13:53:38 EST 2004


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