[Haskell-beginners] Why this order of parameters

Kim-Ee Yeoh ky3 at atamo.com
Fri Nov 13 01:08:41 UTC 2015

On Fri, Nov 13, 2015 at 12:49 AM, Martin Vlk <martin at vlkk.cz> wrote:

> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151113/fcaebf8f/attachment.html>

More information about the Beginners mailing list