summaryrefslogtreecommitdiff
path: root/compiler/utils/Bag.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils/Bag.hs')
-rw-r--r--compiler/utils/Bag.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/utils/Bag.hs b/compiler/utils/Bag.hs
index 5b2c6d56f6..cf7bd123b3 100644
--- a/compiler/utils/Bag.hs
+++ b/compiler/utils/Bag.hs
@@ -6,7 +6,7 @@
Bag: an unordered collection with duplicates
-}
-{-# LANGUAGE ScopedTypeVariables, CPP #-}
+{-# LANGUAGE ScopedTypeVariables, CPP, BangPatterns #-}
module Bag (
Bag, -- abstract type
@@ -33,6 +33,7 @@ import Util
import MonadUtils
import Control.Monad
import Data.Data
+import Data.Semigroup
import Data.Maybe( mapMaybe )
import Data.List ( partition, mapAccumL )
import qualified Data.Foldable as Foldable
@@ -46,6 +47,13 @@ data Bag a
| TwoBags (Bag a) (Bag a) -- INVARIANT: neither branch is empty
| ListBag [a] -- INVARIANT: the list is non-empty
+instance Semigroup (Bag a) where
+ (<>) = unionBags
+
+instance Monoid (Bag a) where
+ mappend = (Data.Semigroup.<>)
+ mempty = emptyBag
+
emptyBag :: Bag a
emptyBag = EmptyBag