
12 Nov
2015
12 Nov
'15
8:08 p.m.
On Fri, Nov 13, 2015 at 12:49 AM, Martin Vlk
I'm curious if this could be for the sake of making the types of the two functions (foldr/foldl) different? E.g. so that you can tell from the type what function it is.
No, that would be foolish. One doesn't simply make the types different to distinguish them. Suppose the elements are already naturally foldable. Then foldr and foldl have the same type signature: foldl, foldr :: (a -> a -> a) -> a -> [a] -> a But sometimes they are only foldable qua another type. Call it r. If you work through Harald's reasoning, you'll arrive at: foldr :: (a -> r -> r) -> r -> [a] -> r foldl :: (r -> a -> r) -> r -> [a] -> r -- Kim-Ee