summaryrefslogtreecommitdiff
path: root/compiler/utils/Bag.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2016-12-09 17:37:28 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2016-12-12 11:56:32 +0000
commitf1036ad80efb9cf80977fa234f8b9c7b23cc6835 (patch)
tree369296f37578b0a2502123b9b0009dd983a37f61 /compiler/utils/Bag.hs
parent818e027e2db2ac291c44a5e07ae151505f3908b8 (diff)
downloadhaskell-f1036ad80efb9cf80977fa234f8b9c7b23cc6835.tar.gz
Make dropDerivedSimples restore [WD] constraints
I'd forgotten to turn [W] + [D] constraints back into [WD] in dropDerivedSimples; and that led to Trac #12936. Fortunately the fix is simple.
Diffstat (limited to 'compiler/utils/Bag.hs')
-rw-r--r--compiler/utils/Bag.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/utils/Bag.hs b/compiler/utils/Bag.hs
index f2b1ead4d8..5fd4ba3b83 100644
--- a/compiler/utils/Bag.hs
+++ b/compiler/utils/Bag.hs
@@ -18,6 +18,7 @@ module Bag (
concatBag, catBagMaybes, foldBag, foldrBag, foldlBag,
isEmptyBag, isSingletonBag, consBag, snocBag, anyBag,
listToBag, bagToList, mapAccumBagL,
+ concatMapBag, mapMaybeBag,
foldrBagM, foldlBagM, mapBagM, mapBagM_,
flatMapBagM, flatMapBagPairM,
mapAndUnzipBagM, mapAccumBagLM,
@@ -30,6 +31,7 @@ import Util
import MonadUtils
import Control.Monad
import Data.Data
+import Data.Maybe( mapMaybe )
import Data.List ( partition, mapAccumL )
import qualified Data.Foldable as Foldable
@@ -216,6 +218,20 @@ mapBag f (UnitBag x) = UnitBag (f x)
mapBag f (TwoBags b1 b2) = TwoBags (mapBag f b1) (mapBag f b2)
mapBag f (ListBag xs) = ListBag (map f xs)
+concatMapBag :: (a -> Bag b) -> Bag a -> Bag b
+concatMapBag _ EmptyBag = EmptyBag
+concatMapBag f (UnitBag x) = f x
+concatMapBag f (TwoBags b1 b2) = unionBags (concatMapBag f b1) (concatMapBag f b2)
+concatMapBag f (ListBag xs) = foldr (unionBags . f) emptyBag xs
+
+mapMaybeBag :: (a -> Maybe b) -> Bag a -> Bag b
+mapMaybeBag _ EmptyBag = EmptyBag
+mapMaybeBag f (UnitBag x) = case f x of
+ Nothing -> EmptyBag
+ Just y -> UnitBag y
+mapMaybeBag f (TwoBags b1 b2) = unionBags (mapMaybeBag f b1) (mapMaybeBag f b2)
+mapMaybeBag f (ListBag xs) = ListBag (mapMaybe f xs)
+
mapBagM :: Monad m => (a -> m b) -> Bag a -> m (Bag b)
mapBagM _ EmptyBag = return EmptyBag
mapBagM f (UnitBag x) = do r <- f x