I wonder if the sumFold example would be clearer if it were written using foldr instead of with foldl. In particular, because sumManual is written with the same kind of recursion as foldr, this would be easier to see:
Turns out, the definition of foldl contains all of that sweet recursive machinery needed to power our manual sum function:
foldr f z [] = z
foldr f z (x:xs) = x `f` foldr f z xs
sumManual [] = 0
sumManual (x:xs) = x + sumManual xs
See how well they line up?
(I really enjoy how this is written overall.)
I wonder if the
sumFoldexample would be clearer if it were written usingfoldrinstead of withfoldl. In particular, becausesumManualis written with the same kind of recursion asfoldr, this would be easier to see:See how well they line up?
(I really enjoy how this is written overall.)