+\begin{code}
+fmapM_maybe :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)
+fmapM_maybe _ Nothing = return Nothing
+fmapM_maybe f (Just x) = do
+ x' <- f x
+ return $ Just x'
+\end{code}
+
+%************************************************************************
+%* *
+\subsection[MaybeT type]{The @MaybeT@ monad transformer}
+%* *
+%************************************************************************
+
+\begin{code}
+
+newtype MaybeT m a = MaybeT {runMaybeT :: m (Maybe a)}
+
+instance Functor m => Functor (MaybeT m) where
+ fmap f x = MaybeT $ fmap (fmap f) $ runMaybeT x
+
+instance Monad m => Monad (MaybeT m) where
+ return = MaybeT . return . Just
+ x >>= f = MaybeT $ runMaybeT x >>= maybe (return Nothing) (runMaybeT . f)
+ fail _ = MaybeT $ return Nothing
+
+\end{code}
+