Proposal: Functor and friends for the wrappers in Data.Monoid

Oleg Grenrus oleg.grenrus at
Sat Feb 21 15:34:04 UTC 2015

I propose to add Functor, Applicative, Monad, Foldable, and Traversable and maybe even MonadFix instances to wrapper newtypes in the Data.Monoid module.
The same way as in the semigroups package, e.g. <>


instance Functor Sum where
  fmap f (Sum x) = Sum (f x)

instance Foldable Sum where
  foldMap f (Sum a) = f a

instance Traversable Sum where
  traverse f (Sum a) = Sum <$> f a

instance Applicative Sum where
  pure = Sum
  a <* _ = a
  _ *> a = a
  Sum f <*> Sum x = Sum (f x)

instance Monad Sum where
  return = Sum
  _ >> a = a
  Sum a >>= f = f a

instance MonadFix Sum where
  mfix f = fix (f . getSum)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <>

More information about the Libraries mailing list