Skip to content

Instantly share code, notes, and snippets.

@kseo
Created March 7, 2016 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kseo/03a66990be5a922c6c4b to your computer and use it in GitHub Desktop.
Save kseo/03a66990be5a922c6c4b to your computer and use it in GitHub Desktop.
fold and Monoid
import Prelude hiding (foldr)
import Data.Monoid
foldComposing :: (a -> (b -> b)) -> [a] -> Endo b
foldComposing f = foldMap (Endo . f)
foldr :: (a -> (b -> b)) -> b -> [a] -> b
foldr f z xs = appEndo (foldComposing f xs) z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment