Difference between revisions of "Talk:Foldr Foldl Foldl'"

From HaskellWiki
Jump to navigation Jump to search
(Created page with "In Section ''Rules of Thumb for Folds'' the following is written:<br> ''... you do not care about the implicit reversal (for example, because your combining function is commut...")
 
Line 17: Line 17:
   
 
I think it would be better to say ''foldl/foldr associates to the left/right.
 
I think it would be better to say ''foldl/foldr associates to the left/right.
  +
  +
--[[User:Klt|Klt]] ([[User talk:Klt|talk]]) 14:28, 19 July 2024 (UTC)

Revision as of 14:28, 19 July 2024

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)