diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2022-01-14 12:11:30 +0000 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-01-14 12:29:12 +0000 |
commit | 2ca5750438a152c701f6b3ae6cd1438e219d9671 (patch) | |
tree | a1145be956686626234d8fc1c48e68a950ad1604 | |
parent | 4b3a0c38209f35fe9cd757f8054769c6880fc4e6 (diff) | |
download | haskell-2ca5750438a152c701f6b3ae6cd1438e219d9671.tar.gz |
bag changes
-rw-r--r-- | compiler/GHC/Data/Bag.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/GHC/Data/Bag.hs b/compiler/GHC/Data/Bag.hs index e314309efc..392922ed85 100644 --- a/compiler/GHC/Data/Bag.hs +++ b/compiler/GHC/Data/Bag.hs @@ -73,7 +73,7 @@ unionManyBags xs = foldr unionBags EmptyBag xs unionBags :: Bag a -> Bag a -> Bag a unionBags EmptyBag b = b -unionBags b EmptyBag = b +--unionBags b EmptyBag = b unionBags b1 b2 = TwoBags b1 b2 consBag :: a -> Bag a -> Bag a @@ -84,13 +84,14 @@ snocBag bag elt = bag `unionBags` (unitBag elt) isEmptyBag :: Bag a -> Bool isEmptyBag EmptyBag = True -isEmptyBag _ = False -- NB invariants +isEmptyBag (TwoBags b1 b2) = isEmptyBag b1 && isEmptyBag b2 +isEmptyBag (ListBag xs) = null xs +isEmptyBag _ = False isSingletonBag :: Bag a -> Bool -isSingletonBag EmptyBag = False -isSingletonBag (UnitBag _) = True -isSingletonBag (TwoBags _ _) = False -- Neither is empty -isSingletonBag (ListBag xs) = isSingleton xs +isSingletonBag b = case bagToList b of + [_] -> True + _ -> False filterBag :: (a -> Bool) -> Bag a -> Bag a filterBag _ EmptyBag = EmptyBag |