3 ms·
> Does it mean "fold elements starting FROM left", or "fold elements TO left" ? Neither; it means "left-associative fold", like left-associative operator: ((a
by a1369209993 4y ago
> Does it mean "fold elements starting FROM left", or "fold elements TO left" ?
Neither; it means "left-associative fold", like left-associative operator: ((a + b) + c).
- MaxBarraclough 4y agoYou've not explained how that differs from folding to the left. It's true than foldl cannot be used with infinite lists, as it will recurse infinitely, unlike foldr. The point to emphasise is that neither foldl nor foldr will swap the ordering of the values in the list, which folding to the left might wrongly imply. That is, if using fold with a function that is associative, foldl and foldr will give the same result, regardless of whether that function is commutative. Wikipedia has a visualisation: https://en.wikipedia.org/wiki/Fold_(higher-order_function)#As_structural_transformations https://en.wikipedia.org/wiki/Fold_(higher-order_function)#A...