Changes between Version 2 and Version 3 of Libraries/Proposals/SemigroupMonoid


Ignore:
Timestamp:
Sep 8, 2017 3:06:17 PM (3 months ago)
Author:
Herbert Valerio Riedel
Comment:

update compatible code example

Legend:

Unmodified
Added
Removed
Modified
  • Libraries/Proposals/SemigroupMonoid

    v2 v3  
    6060 - (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.
    6161
    62 === Phase 2a
     62=== Phase 2a (GHC 8.4) #14191
    6363 - move `Semigroup` class into prelude in anticipation of it becoming a superclass of `Monoid`
    6464
    65 === Phase 2b (either merge with 2a or with 3)
     65=== Phase 2b (GHC 8.4) #14191
    6666
    6767 - Make `Semigroup` a superclass of `Monoid`
     
    7979== Writing compatible code
    8080
     81The code below is expected to be `-Wcompat -Wall` clean
     82(see also https://groups.google.com/forum/#!msg/haskell-core-libraries/PyxpE2ebS9Q/Ni0ywo_GCgAJ)
     83
    8184{{{#!hs
    82 import Data.Semigroup -- re-exports Data.Monoid (w/ Semigroup((<>)))
     85import Data.Semigroup as Sem
     86-- base >= 4.8: `Monoid` class is exported via `Prelude`
     87-- base < 4.11: re-exports `Monoid` class & common newtype wrappers
     88-- base >= 4.11: doesn't reexport `Monoid` class anymore
    8389
    84 instance Semigroup Foo where
     90instance Sem.Semigroup Foo where
    8591  (<>) = …
    8692
     
    8894  mempty = …
    8995
    90 #if !(MIN_VERSION_base(5,0,0))
    91   -- assumption: Semigroup becomes superclass w/ base-5.0.0
     96#if !(MIN_VERSION_base(4,11,0))
     97  -- this is redundant starting with base-4.11 / GHC 8.4
     98  -- if you want to avoid CPP, you can define `mappend = (<>)` unconditionally
    9299  mappend = (<>)
    93100#endif
    94101}}}
    95102
     103If you need compatiblity with GHC prior to version 8.0 you can avoid -XCPP by depending conditionally on `semigroups` via
     104
     105{{{
     106if !impl(ghc >= 8.0)
     107  build-depends: semigroups == 0.18.*
     108}}}
     109
     110to provide a legacy `Semigroup` class.
     111
    96112----
    97113