Haskell foldr in terms of foldl

This explains foldl in terms of foldr : https://ratndeo.wordpress.com/2013/01/11/haskell-foldl-as-foldr/

Now its time to whisper foldr in terms of foldl :

foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f init (x:xs) = foldl f’ (f x) xs init
where f’ g y = g . f y

foldr _ init [] = init

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s