[Haskell-cafe] Flattening tail recursion?

GoldPython goldpython at gmail.com
Fri Dec 10 10:06:54 EST 2004


I'm missing something, a functional idiom, whatever. I know there's
"length" to count the elements in a list and it works fine, but the
function below stack overflows on a large list.

   countLines [] = 0
   countLines (_:ls) = 1 + countLines ls

I would have thought that this was tail recursive and would be
flattened into iteration by the compiler. Can anyone explain why? Is
it because the call is embedded in an expression?

And additionally, how can I predict when the flattening will occur?

Thanks,
Will


More information about the Haskell-Cafe mailing list