Skip to content

Commit 09bc4f6

Browse files
committed
Add Semigroup instances for base>=4.9
This makes unordered-containers `-Wcompat`-clean on GHC HEAD See also ekmett/semigroups#56
1 parent 0696e2d commit 09bc4f6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Data/HashMap/Base.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ import Data.Monoid (Monoid(mempty, mappend))
9595
import Data.Traversable (Traversable(..))
9696
import Data.Word (Word)
9797
#endif
98+
#if __GLASGOW_HASKELL__ >= 711
99+
import Data.Semigroup (Semigroup((<>)))
100+
#endif
98101
import Control.DeepSeq (NFData(rnf))
99102
import Control.Monad.ST (ST)
100103
import Data.Bits ((.&.), (.|.), complement)
@@ -163,10 +166,20 @@ instance Functor (HashMap k) where
163166
instance Foldable.Foldable (HashMap k) where
164167
foldr f = foldrWithKey (const f)
165168

169+
#if __GLASGOW_HASKELL__ >= 711
170+
instance (Eq k, Hashable k) => Semigroup (HashMap k v) where
171+
(<>) = union
172+
{-# INLINE (<>) #-}
173+
#endif
174+
166175
instance (Eq k, Hashable k) => Monoid (HashMap k v) where
167176
mempty = empty
168177
{-# INLINE mempty #-}
178+
#if __GLASGOW_HASKELL__ >= 711
179+
mappend = (<>)
180+
#else
169181
mappend = union
182+
#endif
170183
{-# INLINE mappend #-}
171184

172185
instance (Data k, Data v, Eq k, Hashable k) => Data (HashMap k v) where

Data/HashSet.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ import Control.DeepSeq (NFData(..))
7676
import Data.Data hiding (Typeable)
7777
import Data.HashMap.Base (HashMap, foldrWithKey)
7878
import Data.Hashable (Hashable(hashWithSalt))
79-
#if __GLASGOW_HASKELL__ < 709
79+
#if __GLASGOW_HASKELL__ >= 711
80+
import Data.Semigroup (Semigroup(..), Monoid(..))
81+
#elif __GLASGOW_HASKELL__ < 709
8082
import Data.Monoid (Monoid(..))
8183
#endif
8284
import GHC.Exts (build)
@@ -114,10 +116,20 @@ instance Foldable.Foldable HashSet where
114116
foldr = Data.HashSet.foldr
115117
{-# INLINE foldr #-}
116118

119+
#if __GLASGOW_HASKELL__ >= 711
120+
instance (Hashable a, Eq a) => Semigroup (HashSet a) where
121+
(<>) = union
122+
{-# INLINE (<>) #-}
123+
#endif
124+
117125
instance (Hashable a, Eq a) => Monoid (HashSet a) where
118126
mempty = empty
119127
{-# INLINE mempty #-}
128+
#if __GLASGOW_HASKELL__ >= 711
129+
mappend = (<>)
130+
#else
120131
mappend = union
132+
#endif
121133
{-# INLINE mappend #-}
122134

123135
instance (Eq a, Hashable a, Read a) => Read (HashSet a) where

0 commit comments

Comments
 (0)