Skip to content

Instantly share code, notes, and snippets.

@onlyshk
Created November 4, 2011 06:47
Show Gist options
  • Save onlyshk/1338805 to your computer and use it in GitHub Desktop.
Save onlyshk/1338805 to your computer and use it in GitHub Desktop.
foldl and foldr
foldl :: (b -> a -> b) -> b -> [a] -> b
foldl _ z [] = z
foldl f z (x:xs) = foldl f (f z x) xs
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr _ z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment