:: Monad m => (m (m a)) -> m a

The join function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level.

Examples

A common use of join is to run an IO computation returned from an STM transaction, since STM transactions can't perform IO directly. Recall that
atomically :: STM a -> IO a
is used to run STM transactions atomically. So, by specializing the types of atomically and join to
atomically :: STM (IO b) -> IO (IO b)
join       :: IO (IO b)  -> IO b
we can compose them as
join . atomically :: STM (IO b) -> IO b
to run an STM transaction and the IO action it returns.
Compute the diagonal of a matrix
>>> diagonal (V2 (V2 a b) (V2 c d))
V2 a d
This is simply fmap fold . sequence.