Add `Monad (Compose m t)`
Motivation
Monad
is not closed under Compose
generally, but if t
is Traversable
, m . t
is Monad
for any Monad m
.
Thus, I propose to add an instance Monad (Compose m t)
in Data.Functor.Compose
.
Proposal
Add the following code in Data.Functor.Compose
.
(>>=.) :: (Monad m, Monad t, Traversable t) => m (t a) -> (a -> m (t b)) -> m (t b)
x >>=. f = x >>= (<$>) join . mapM f
instance (Monad m, Monad t, Traversable t) => Monad (Compose m t) where
(Compose c) >>= f = Compose $ c >>=. (getCompose . f)