Haskell foldl as foldr

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

at first definition of f’ looks puzzling , but if we looks at step fxn in foldr :
a->b->b

so (in easy to say words ) f’ is just preserving order of operands and with foldr we are creating a chain .

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

One Response to Haskell foldl as foldr

  1. Pingback: Haskell foldr in terms of foldl | Ratn's Blog

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