monoid-transformer-0.0.3: src/Data/Monoid/MonadicEndo.hs
module Data.Monoid.MonadicEndo where
import Data.Monoid (Monoid, mempty, mappend, )
{- |
Like Data.Monoid.Endo but with monadic result.
'mempty' is 'return' and 'mappend' is '<=<'.
Useful e.g. for handling options with GetOpt.
-}
newtype T m a = Cons {run :: a -> m a}
instance Monad m => Monoid (T m a) where
mempty = Cons return
mappend (Cons x) (Cons y) =
Cons $ (x =<<) . y
-- Cons $ x <=< y