Talk:Foldr Foldl Foldl'

Add topic
From HaskellWiki

In Section Rules of Thumb for Folds the following is written:
... you do not care about the implicit reversal (for example, because your combining function is commutative like ...
Does this suggest that when your binary operator is commutative, foldl and fold r give the same result?
But that is not true! If the operation is associative then you get always the same result (if both deliver a result).
I can provide a commutative example where foldl and foldr return different result.

Moreover foldl' conceptually reverses the order of the list is a misleading formulation:
divisel :: [Double] -> Double divisel = foldl (/) 1

diviser :: [Double] -> Double diviser = foldr (/) 1

divisel [1,2] = diviser [1,2] = 0.5
Both divide 1 by 2.

I think it would be better to say foldl/foldr associates to the left/right.

--Klt (talk) 14:28, 19 July 2024 (UTC)

As the original author of the erroneous language, I think you are right.

CarlEdman (talk) 15:07, 19 July 2024 (UTC)