summaryrefslogtreecommitdiff
path: root/compiler/utils/MonadUtils.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2018-09-28 14:22:48 +0200
committerKrzysztof Gogolewski <krz.gogolewski@gmail.com>2018-09-28 14:22:48 +0200
commite72d7880b940881d38b8c3db9a00d5d007b1458f (patch)
tree1258fcace7d78fd274471f17d75f7e45c4957cfb /compiler/utils/MonadUtils.hs
parentd00c308633fe7d216d31a1087e00e63532d87d6d (diff)
downloadhaskell-e72d7880b940881d38b8c3db9a00d5d007b1458f.tar.gz
Normalise EmptyCase types using the constraint solver
Summary: Certain `EmptyCase` expressions were mistakently producing warnings since their types did not have as many type families reduced as they could have. The most direct way to fix this is to normalise these types initially using the constraint solver to solve for any local equalities that may be in scope. Test Plan: make test TEST=T14813 Reviewers: simonpj, bgamari, goldfire Reviewed By: simonpj Subscribers: rwbarton, carter GHC Trac Issues: #14813 Differential Revision: https://phabricator.haskell.org/D5094
Diffstat (limited to 'compiler/utils/MonadUtils.hs')
-rw-r--r--compiler/utils/MonadUtils.hs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/utils/MonadUtils.hs b/compiler/utils/MonadUtils.hs
index 39a76e1cf2..e86bc49708 100644
--- a/compiler/utils/MonadUtils.hs
+++ b/compiler/utils/MonadUtils.hs
@@ -21,6 +21,7 @@ module MonadUtils
, foldlM, foldlM_, foldrM
, maybeMapM
, whenM, unlessM
+ , filterOutM
) where
-------------------------------------------------------------------------------
@@ -31,6 +32,7 @@ import GhcPrelude
import Maybes
+import Control.Applicative
import Control.Monad
import Control.Monad.Fix
import Control.Monad.IO.Class
@@ -199,3 +201,8 @@ whenM mb thing = do { b <- mb
unlessM :: Monad m => m Bool -> m () -> m ()
unlessM condM acc = do { cond <- condM
; unless cond acc }
+
+-- | Like 'filterM', only it reverses the sense of the test.
+filterOutM :: (Applicative m) => (a -> m Bool) -> [a] -> m [a]
+filterOutM p =
+ foldr (\ x -> liftA2 (\ flg -> if flg then id else (x:)) (p x)) (pure [])