[Haskell-cafe] foldl in terms of foldr

Henning Thielemann lemming at henning-thielemann.de
Tue Jan 26 11:37:08 EST 2010


On Tue, 26 Jan 2010, Xingzhi Pan wrote:

> Hi,
>
> I am reading Real World Haskell and have some questions about the
> piece of code implementing foldl in terms of foldr:
>
> -- file: ch04/Fold.hs
> myFoldl :: (a -> b -> a) -> a -> [b] -> a
> myFoldl f z xs = foldr step id xs z
>    where step x g a = g (f a x)
>
> The first argument to foldr is of type (a -> b -> a), which takes 2
> arguments.  But 'step' here is defined as a function taking 3
> arguments.  What am I missing here?  (Partial application?  The order
> of execution?)

http://www.haskell.org/haskellwiki/Foldl_as_foldr

> Btw, is there a way I can observe the type signature of 'step' in this code?

http://www.haskell.org/haskellwiki/Determining_the_type_of_an_expression


More information about the Haskell-Cafe mailing list