... | ... | @@ -93,6 +93,9 @@ mappend = (<>) |
|
|
## Writing compatible code
|
|
|
|
|
|
|
|
|
### Recommended Variant
|
|
|
|
|
|
|
|
|
|
|
|
The code below is expected to be `-Wcompat -Wall` clean
|
|
|
(see also [ https://groups.google.com/forum/\#!msg/haskell-core-libraries/PyxpE2ebS9Q/Ni0ywo_GCgAJ](https://groups.google.com/forum/#!msg/haskell-core-libraries/PyxpE2ebS9Q/Ni0ywo_GCgAJ))
|
... | ... | @@ -130,6 +133,49 @@ if !impl(ghc >= 8.0) |
|
|
to provide a legacy `Semigroup` class.
|
|
|
|
|
|
|
|
|
### Alternative w/ conditionally defined `Semigroup` instance & -XCPP
|
|
|
|
|
|
|
|
|
|
|
|
This variant can be used if you require support for GHC \< 8.0 **and** you do **not** want to depend on the `semigroups` package.
|
|
|
|
|
|
|
|
|
```
|
|
|
#if MIN_VERSION_base(4,9,0)
|
|
|
-- Data.Semigroup was added in base-4.9
|
|
|
import Data.Semigroup as Sem
|
|
|
#endif
|
|
|
#if !(MIN_VERSION_base(4,8,0))
|
|
|
-- starting with base-4.8, Monoid is rexported from Prelude
|
|
|
import Data.Monoid
|
|
|
#endif
|
|
|
|
|
|
appendFoo :: Foo -> Foo -> Foo
|
|
|
appendFoo = …
|
|
|
|
|
|
emptyFoo :: Foo
|
|
|
emptyFoo = …
|
|
|
|
|
|
#if MIN_VERSION_base(4,9,0)
|
|
|
instance Sem.Semigroup Foo where
|
|
|
(<>) = appendFoo
|
|
|
#endif
|
|
|
|
|
|
instance Monoid Foo where
|
|
|
mempty = emptyFoo
|
|
|
|
|
|
#if MIN_VERSION_base(4,11,0)
|
|
|
-- starting with base-4.11, mappend definitions are redundant;
|
|
|
-- at some point `mappend` will be removed from `Monoid`
|
|
|
#elif MIN_VERSION_base(4,9,0)
|
|
|
mappend = (Sem.<>)
|
|
|
#else // base < 4.9
|
|
|
-- prior to GHC 8.0 / base-4.9 where no `Semigroup` class existed
|
|
|
mappend = appendFoo
|
|
|
# endif
|
|
|
|
|
|
```
|
|
|
|
|
|
---
|
|
|
|
|
|
|
... | ... | |