Extending comments: as shown in questions , you need to have some function n (ma) -> m (na) in order to be able to make the composition a monad.
If your inner monad is Traversable , then sequence provides such a function, and the following will be of the correct type:
(>>>=) :: (Monad m, Monad n, Traversable n) => m (na) -> (a -> m (nb)) -> m (nb) m >>>= k = do a <- m b <- sequence (map ka) return (join b)
A few well-known transformers are actually simple newtype wrappers over something equivalent to this (although basically things are defined with matching patterns, and not literally using instances of the internal monad Monad and Traversable ):
MaybeT based on MaybeEither Based on EitherWriterT based on (,) ( (,) usually does not have a specific Monad instance, and WriterT uses the wrong order of tuples to use it if it had - but in a spirit that it could have).ListT based on [] . Oh, screaming ...
The latter, in fact, is notorious that it is not a monad if the raised monad is โcommutativeโ, otherwise expressions that must be equal to the laws of the monad can produce different orders of effects. My guess is that this comes essentially from lists, which can contain more than one value, unlike other reliably working examples.
So, although the above definition will be correctly printed, it can still violate the laws of the monad.
Just like an afterthought, another transformer is such a nested monad, but in a completely different way: ReaderT , based on the use of (->) as the external monad.
source share