In Haskell Wikibook, foldr is implemented as follows:
foldr :: (a -> b -> b) -> b -> [a] -> b foldr f acc [] = acc foldr f acc (x:xs) = fx (foldr f acc xs)
It is stated that the initial value of the battery is specified as an argument. But, as I understand it, acc is the identity value for the operation (for example, 0 for the sum or 1 for the product), and its value does not change during the execution of the function. Why then is it referred to here and in other texts as a battery, implying that it changes or accumulates the value step by step?
I see that the battery matters in the left fold, for example foldl, but is the wikibook explanation wrong and only for symmetry, in which case is it wrong?
haskell
andro
source share