I wanted to ask, if the function foldl
is a tail recursion?
When I look at the source, how foldl
is implemented:
foldl :: (b -> a -> b) -> b -> [a] -> b
foldl f acc [] = acc
foldl f acc (x:xs) = foldl f (f acc x) xs
it looks like a tail recursion.
Fold left is always left associated. Assumed I have following expression:
foldl (*) 1 [1..3]
then it will evaluate to:
((1 * 1) * 2) * 3
then write out the steps, I would do like:
foldl (*) 1 [1..3] =
foldl (*) (1 * 1) [2,3]
foldl (*) (1 * 2) [3]
foldl (*) (2 * 3) []
6
not like ((1 * 1) * 2) * 3
, or am I wrong?