The tool you are looking for already exists. There are two Kleisli composition operators in Control.Monad.
(>=>) :: Monad m => (a -> mb) -> (b -> mc) -> a -> mc (<=<) :: Monad m => (b -> mc) -> (a -> mb) -> a -> mc
When m = Perhaps the implementation of composeMaybe will be implemented:
composeMaybe = (>=>)
Looking at the definition (>=>) ,
f >=> g = \x -> fx >>= g
which you can embed if you want to think about it in your own terms as
composeMaybe fgx = fx >>= g
or which can be written in do -sugar as:
composeMaybe fgx = do y <- fx gy
In general, I just stick with the use (>=>) , which has good theoretical reasons for the existing one, since it provides the cleanest way to state the laws of the monad.
source share