Skip to content

Commit

Permalink
Add Semigroup instances for Map and Set
Browse files Browse the repository at this point in the history
This fixes the build on GHC 8.4.1.
  • Loading branch information
RyanGlScott committed Jan 3, 2018
1 parent 6903039 commit 32c766d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 12 additions & 1 deletion Data/HashMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion Data/HashSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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) $
Expand Down

0 comments on commit 32c766d

Please sign in to comment.