projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use braces rather than angle-brackets in debug-printing for Bags
[ghc-hetmet.git]
/
compiler
/
utils
/
MonadUtils.hs
diff --git
a/compiler/utils/MonadUtils.hs
b/compiler/utils/MonadUtils.hs
index
2064657
..
9b364ae
100644
(file)
--- a/
compiler/utils/MonadUtils.hs
+++ b/
compiler/utils/MonadUtils.hs
@@
-18,7
+18,8
@@
module MonadUtils
, concatMapM
, mapMaybeM
, anyM, allM
, concatMapM
, mapMaybeM
, anyM, allM
- , foldlM, foldrM
+ , foldlM, foldlM_, foldrM
+ , maybeMapM
) where
----------------------------------------------------------------------------------------
) where
----------------------------------------------------------------------------------------
@@
-145,7
+146,16
@@
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
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
foldrM k z (x:xs) = do { r <- foldrM k z xs; k x r }
-- | Monadic version of foldr
foldrM :: (Monad m) => (b -> a -> m a) -> a -> [b] -> m a
foldrM _ z [] = return z
foldrM k z (x:xs) = do { r <- foldrM k z xs; k x r }
+
+-- | Monadic version of fmap specialised for Maybe
+maybeMapM :: Monad m => (a -> m b) -> (Maybe a -> m (Maybe b))
+maybeMapM _ Nothing = return Nothing
+maybeMapM m (Just x) = liftM Just $ m x