X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=compiler%2Futils%2FMonadUtils.hs;h=5e01a222b21bdb917853c6c416d5175efbeb98e1;hb=2662dbc5b2c30fc11ccb99e7f9b2dba794d680ba;hp=733eda17005dbac5ba482493241ca368735915d1;hpb=5e5a08eb37f5513cecb47101a97fdaf09c4be040;p=ghc-hetmet.git diff --git a/compiler/utils/MonadUtils.hs b/compiler/utils/MonadUtils.hs index 733eda1..5e01a22 100644 --- a/compiler/utils/MonadUtils.hs +++ b/compiler/utils/MonadUtils.hs @@ -8,6 +8,8 @@ module MonadUtils , MonadFix(..) , MonadIO(..) + + , ID, runID , liftIO1, liftIO2, liftIO3, liftIO4 @@ -18,10 +20,12 @@ module MonadUtils , concatMapM , mapMaybeM , anyM, allM - , foldlM, foldrM + , foldlM, foldlM_, foldrM , maybeMapM ) where +import Outputable + ---------------------------------------------------------------------------------------- -- Detection of available libraries ---------------------------------------------------------------------------------------- @@ -43,6 +47,20 @@ import Control.Monad import Control.Monad.Fix ---------------------------------------------------------------------------------------- +-- The ID monad +---------------------------------------------------------------------------------------- + +newtype ID a = ID a +instance Monad ID where + return x = ID x + (ID x) >>= f = f x + _ >> y = y + fail s = panic s + +runID :: ID a -> a +runID (ID x) = x + +---------------------------------------------------------------------------------------- -- MTL ---------------------------------------------------------------------------------------- @@ -146,6 +164,10 @@ allM f (b:bs) = (f b) >>= (\bv -> if bv then allM f bs else return False) foldlM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a foldlM = foldM +-- | Monadic version of foldl that discards its result +foldlM_ :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m () +foldlM_ = foldM_ + -- | Monadic version of foldr foldrM :: (Monad m) => (b -> a -> m a) -> a -> [b] -> m a foldrM _ z [] = return z