diff --git a/CHANGES b/CHANGES index f2d2e1c..ad284aa 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ += Version next, ????-??-?? = +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +* Add Semigroup instances for Map and Set + = Version 1.3.2, 2016-11-30 = ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * Replace internal use of deprecated containers functions diff --git a/Data/HashMap.hs b/Data/HashMap.hs index 2df95c2..4513ce0 100644 --- a/Data/HashMap.hs +++ b/Data/HashMap.hs @@ -122,6 +122,9 @@ import Data.Hashable import Data.Foldable (Foldable(foldMap)) import Data.List (foldl') import Data.Monoid (Monoid(..)) +#if MIN_VERSION_base(4,9,0) +import Data.Semigroup (Semigroup((<>), stimes), stimesIdempotentMonoid) +#endif import Data.Traversable (Traversable(traverse)) import Data.Typeable @@ -178,8 +181,16 @@ instance Functor (Map k) where instance Ord k => Monoid (Map k a) where mempty = empty - mappend = union mconcat = unions +#if !(MIN_VERSION_base(4,9,0)) + mappend = union +#else + mappend = (<>) + +instance Ord k => Semigroup (Map k a) where + (<>) = union + stimes = stimesIdempotentMonoid +#endif instance Foldable (Map k) where foldMap f (Map m) = foldMap some_fold m diff --git a/Data/HashSet.hs b/Data/HashSet.hs index fe31554..4f2951a 100644 --- a/Data/HashSet.hs +++ b/Data/HashSet.hs @@ -73,6 +73,9 @@ import Control.DeepSeq import Data.Hashable import Data.List (foldl') import Data.Monoid (Monoid(..)) +#if MIN_VERSION_base(4,9,0) +import Data.Semigroup (Semigroup((<>), stimes), stimesIdempotentMonoid) +#endif import Data.Typeable #if __GLASGOW_HASKELL__ @@ -117,8 +120,16 @@ instance NFData a => NFData (Set a) where instance Ord a => Monoid (Set a) where mempty = empty - mappend = union mconcat = unions +#if !(MIN_VERSION_base(4,9,0)) + mappend = union +#else + mappend = (<>) + +instance Ord a => Semigroup (Set a) where + (<>) = union + stimes = stimesIdempotentMonoid +#endif instance Show a => Show (Set a) where showsPrec d m = showParen (d > 10) $