From b39fa8053b05a48b7bd74e63e8dec1f729fda324 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 12 Dec 2007 13:50:55 +0000 Subject: [PATCH] Added two more monadic helper functions to the Utils module --- common/Utils.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/Utils.hs b/common/Utils.hs index eed2f72..67de22d 100644 --- a/common/Utils.hs +++ b/common/Utils.hs @@ -154,6 +154,18 @@ modifyM f = do st <- get put st' return x +-- | Applies a monadic modification to the state in a StateT wrapper. +modifyM_ :: Monad m => (s -> m s) -> StateT s m () +modifyM_ f = do st <- get + st' <- lift $ f st + put st' + return () + +-- | Like lift, but instead of applying to a monadic action (m b), applies to a function (a -> m b). +liftF :: (MonadTrans t, Monad m) => (a -> m b) -> (a -> t m b) +liftF f x = lift (f x) + + -- | Like the (.) operator, but for monads. (<.<) :: Monad m => (b -> m c) -> (a -> m b) -> (a -> m c) (<.<) f1 f0 x = f0 x >>= f1