... | ... | @@ -69,12 +69,12 @@ mappend = (<>) |
|
|
|
|
|
- (maybe) Implement a warning about definitions of an operator named `(<>)` that indicate it will be coming into Prelude in 8.2. We should warn about missing Semigroup instances at any use site of `(<>)` as they'll break in 8.2.
|
|
|
|
|
|
### Phase 2a
|
|
|
### Phase 2a (GHC 8.4) \#14191
|
|
|
|
|
|
|
|
|
- move `Semigroup` class into prelude in anticipation of it becoming a superclass of `Monoid`
|
|
|
|
|
|
### Phase 2b (either merge with 2a or with 3)
|
|
|
### Phase 2b (GHC 8.4) \#14191
|
|
|
|
|
|
|
|
|
- Make `Semigroup` a superclass of `Monoid`
|
... | ... | @@ -93,21 +93,43 @@ mappend = (<>) |
|
|
## Writing compatible code
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
```
|
|
|
import Data.Semigroup -- re-exports Data.Monoid (w/ Semigroup((<>)))
|
|
|
import Data.Semigroup as Sem
|
|
|
-- base >= 4.8: `Monoid` class is exported via `Prelude`
|
|
|
-- base < 4.11: re-exports `Monoid` class & common newtype wrappers
|
|
|
-- base >= 4.11: doesn't reexport `Monoid` class anymore
|
|
|
|
|
|
instance Semigroup Foo where
|
|
|
instance Sem.Semigroup Foo where
|
|
|
(<>) = …
|
|
|
|
|
|
instance Monoid Foo where
|
|
|
mempty = …
|
|
|
|
|
|
#if !(MIN_VERSION_base(5,0,0))
|
|
|
-- assumption: Semigroup becomes superclass w/ base-5.0.0
|
|
|
#if !(MIN_VERSION_base(4,11,0))
|
|
|
-- this is redundant starting with base-4.11 / GHC 8.4
|
|
|
-- if you want to avoid CPP, you can define `mappend = (<>)` unconditionally
|
|
|
mappend = (<>)
|
|
|
#endif
|
|
|
```
|
|
|
|
|
|
|
|
|
If you need compatiblity with GHC prior to version 8.0 you can avoid -XCPP by depending conditionally on `semigroups` via
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
if !impl(ghc >= 8.0)
|
|
|
build-depends: semigroups == 0.18.*
|
|
|
```
|
|
|
|
|
|
|
|
|
to provide a legacy `Semigroup` class.
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
... | ... | |