summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/utils/MonadUtils.hs11
1 files changed, 5 insertions, 6 deletions
diff --git a/compiler/utils/MonadUtils.hs b/compiler/utils/MonadUtils.hs
index 5c28aa5f39..936ae62751 100644
--- a/compiler/utils/MonadUtils.hs
+++ b/compiler/utils/MonadUtils.hs
@@ -32,7 +32,7 @@ import Control.Applicative
import Control.Monad
import Control.Monad.Fix
import Control.Monad.IO.Class
-import Data.Foldable (sequenceA_)
+import Data.Foldable (sequenceA_, foldr)
import Data.List (unzip4, unzip5, zipWith4)
-------------------------------------------------------------------------------
@@ -191,17 +191,16 @@ orM :: Monad m => m Bool -> m Bool -> m Bool
orM m1 m2 = m1 >>= \x -> if x then return True else m2
-- | Monadic version of foldl
-foldlM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
+foldlM :: (Monad m, Foldable t) => (a -> b -> m a) -> a -> t b -> m a
foldlM = foldM
-- | Monadic version of foldl that discards its result
-foldlM_ :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()
+foldlM_ :: (Monad m, Foldable t) => (a -> b -> m a) -> a -> t 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 }
+foldrM :: (Monad m, Foldable t) => (b -> a -> m a) -> a -> t b -> m a
+foldrM k z x = foldr (\x r -> r >>= k x) (pure z) x
-- | Monadic version of fmap specialised for Maybe
maybeMapM :: Monad m => (a -> m b) -> (Maybe a -> m (Maybe b))