Skip to content
Snippets Groups Projects
Commit d23ffcf4 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel :man_dancing:
Browse files

Replace internal `class Semigroup` fork by original class

in favour of the real `class Semigroup` provided by the canonical
`semigroups` package for GHC < 8.0

This way we can properly provide `Semigroup` instances as well a
`NonEmpty` lists in Cabal's public API in a uniform way for older GHCs
before GHC 8.0/base-4.9

NB: This incurs a dependency on `semigroups` *only* for GHC versions
    prior to GHC 8.0; similar to the pre-existing conditional
    dependency on the `fail` package
parent b7067783
No related branches found
No related tags found
No related merge requests found
......@@ -283,9 +283,9 @@ library
ghc-options: -Wcompat -Wnoncanonical-monad-instances
-Wnoncanonical-monadfail-instances
else
-- at least one of lib:Cabal's dependency (`parsec`)
-- already depends on `fail` transitively
build-depends: fail == 4.9.*
-- at least one of lib:Cabal's dependency (i.e. `parsec`)
-- already depends on `fail` and `semigroups` transitively
build-depends: fail == 4.9.*, semigroups >= 0.18.3 && < 0.20
exposed-modules:
Distribution.Backpack
......
......@@ -25,6 +25,7 @@
* Change the arguments of `Newtype` class to better suit @DeriveAnyClass@ usage,
add default implementation in terms of `coerce` / `unsafeCoerce`.
* Implement support for response file arguments to defaultMain* and cabal-install.
* Uniformly provide 'Semigroup' instances for `base < 4.9` via `semigroups` package
----
......
......@@ -23,85 +23,12 @@ module Distribution.Compat.Semigroup
import Distribution.Compat.Binary (Binary)
import GHC.Generics
#if __GLASGOW_HASKELL__ >= 711
-- Data.Semigroup is available since GHC 8.0/base-4.9
-- Data.Semigroup is available since GHC 8.0/base-4.9 in `base`
-- for older GHC/base, it's provided by `semigroups`
import Data.Semigroup
import qualified Data.Monoid as Mon
#else
-- provide internal simplified non-exposed class for older GHCs
import Data.Monoid as Mon (Monoid(..), All(..), Any(..), Dual(..))
-- containers
import Data.Set (Set)
import Data.IntSet (IntSet)
import Data.Map (Map)
import Data.IntMap (IntMap)
class Semigroup a where
(<>) :: a -> a -> a
-- several primitive instances
instance Semigroup () where
_ <> _ = ()
instance Semigroup [a] where
(<>) = (++)
instance Semigroup a => Semigroup (Dual a) where
Dual a <> Dual b = Dual (b <> a)
instance Semigroup a => Semigroup (Maybe a) where
Nothing <> b = b
a <> Nothing = a
Just a <> Just b = Just (a <> b)
instance Semigroup (Either a b) where
Left _ <> b = b
a <> _ = a
instance Semigroup Ordering where
LT <> _ = LT
EQ <> y = y
GT <> _ = GT
instance Semigroup b => Semigroup (a -> b) where
f <> g = \a -> f a <> g a
instance Semigroup All where
All a <> All b = All (a && b)
instance Semigroup Any where
Any a <> Any b = Any (a || b)
instance (Semigroup a, Semigroup b) => Semigroup (a, b) where
(a,b) <> (a',b') = (a<>a',b<>b')
instance (Semigroup a, Semigroup b, Semigroup c)
=> Semigroup (a, b, c) where
(a,b,c) <> (a',b',c') = (a<>a',b<>b',c<>c')
instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d)
=> Semigroup (a, b, c, d) where
(a,b,c,d) <> (a',b',c',d') = (a<>a',b<>b',c<>c',d<>d')
instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e)
=> Semigroup (a, b, c, d, e) where
(a,b,c,d,e) <> (a',b',c',d',e') = (a<>a',b<>b',c<>c',d<>d',e<>e')
-- containers instances
instance Semigroup IntSet where
(<>) = mappend
instance Ord a => Semigroup (Set a) where
(<>) = mappend
instance Semigroup (IntMap v) where
(<>) = mappend
instance Ord k => Semigroup (Map k v) where
(<>) = mappend
#endif
-- | A copy of 'Data.Semigroup.First'.
newtype First' a = First' { getFirst' :: a }
deriving (Eq, Ord, Show)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment