Data.Monoid

Ross Paterson ross at soi.city.ac.uk
Tue Sep 13 11:52:31 EDT 2005


(regurgitating
http://www.haskell.org/pipermail/libraries/2005-July/004057.html)

I propose to replace the instance

	instance Monoid (a -> a) where
		mempty  = id
		mappend = (.)

with

	newtype Endo a = Endo { runEndo :: a -> a }

	instance Monoid (Endo a) where
		mempty = Endo id
		Endo f `mappend` Endo g = Endo (f . g)

	instance Monoid b => Monoid (a -> b) where
		mempty _ = mempty
		mappend f g x = f x `mappend` g x



More information about the Libraries mailing list