On Fri, 10 Dec 2004, Robert Dockins wrote: > > 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? > > countlines = aux 0 > where aux x [] = x > aux x (_:ls) > | x `seq` False = undefined > | otherwise = aux (x+1) ls > > The `seq` causes the x to be evaluated, so it should run in constant space.
Is it also possible to do that with 'foldl'? Why is Prelude.length not defined this way (according to the Haskell98 report)? _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
