
2 Feb
2016
2 Feb
'16
8:55 p.m.
On Tue, Feb 02, 2016 at 05:52:08PM -0700, derek riemer wrote:
Doesn't foldr have to "reach" to the far right of the list of infinite primes to get the last number since it consumes from the right?
foldl is /left/ associative, foldr /right/ associative. λ> foldl1 (-) [1..3] -4 -- which is: ((1-2)-3) λ> foldr1 (-) [1..3] 2 -- which is (1-(2-3)) Haskell being non strict (i.e. "proceeding from the outside"), it will immediately short circuit on foldr but have to build the whole list first on foldl.