News for hackers. Stuff that matters.
Re:It never makes sense to use foldl on lists in Haskell (2019) by pansa2 on Friday March 20, 2020 @08:39PM (#22643216)
> If your language uses strict evaluation (like most languages), it probably makes sense to use a left fold on lists.

The standard libraries of strict languages agree. Python's `functools.reduce` and JavaScript's `Array.prototype.reduce` perform strict left folds equivalent to Haskell's `foldl'`.

Interestingly, JavaScript also has `Array.prototype.reduceRight`, but it's not equivalent to a `foldr`. It processes the list from right-to-left, so is approximately equivalent to `reverse` followed by `foldl'`.

Re:It never makes sense to use foldl on lists in Haskell (2019) by skrebbel on Saturday March 21, 2020 @03:32AM (#22645179)
> Interestingly, JavaScript also has `Array.prototype.reduceRight`, but it's not equivalent to a `foldr`. It processes the list from right-to-left, so is approximately equivalent to `reverse` followed by `foldl'`.

I don't understand how that's different in practice. Can you elaborate?

Re:It never makes sense to use foldl on lists in Haskell (2019) by pansa2 on Saturday March 21, 2020 @04:31AM (#22645330)
Although `foldr` accumulates the result right-to-left, it processes the list left-to-right, which allows it to short-circuit.

`reduceRight` processes and accumulates right-to-left, so it doesn’t have the short-circuiting ability of `foldr`.

Re:It never makes sense to use foldl on lists in Haskell (2019) by skrebbel on Saturday March 21, 2020 @05:22AM (#22645450)
Right! Super clear, thanks :-)