[Haskell-beginners] Why this order of parameters
Martin Vlk
martin at vlkk.cz
Thu Nov 12 17:49:20 UTC 2015
I think again this technically doesn't matter...
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.
(I'm a Haskell beginner myself so would be curious to hear an expert's
voice on this!)
Martin
martin:
> foldl :: (a -> b -> a) -> a -> [b] -> a
> foldr :: (a -> b -> b) -> b -> [a] -> b
>
> For once the list is a list of as in foldl, but a list of as in foldr. Now that can be fixed with renaming the type
> parameters
>
> foldr :: (b -> a -> a) -> a -> [b] -> a
>
> this is the exact same thing and resembles more the type of foldl. But still the function argument has its parameters
> flipped. foldl's function takes the list element as second parameter and foldr's takes it as first parameter.
>
> Why is that so?
More information about the Beginners
mailing list