Changes between Version 4 and Version 5 of Libraries/Proposals/SemigroupMonoid


Ignore:
Timestamp:
Sep 16, 2017 5:22:05 PM (3 months ago)
Author:
Herbert Valerio Riedel
Comment:

try to describe ugly alternative variant

Legend:

Unmodified
Added
Removed
Modified
  • Libraries/Proposals/SemigroupMonoid

    v4 v5  
    7979== Writing compatible code
    8080
     81=== Recommended Variant
     82
    8183The code below is expected to be `-Wcompat -Wall` clean
    8284(see also https://groups.google.com/forum/#!msg/haskell-core-libraries/PyxpE2ebS9Q/Ni0ywo_GCgAJ)
     
    110112to provide a legacy `Semigroup` class.
    111113
     114=== Alternative w/ conditionally defined `Semigroup` instance & -XCPP
     115
     116This variant can be used if you require support for GHC < 8.0 **and** you do **not** want to depend on the `semigroups` package.
     117
     118{{{#!hs
     119#if MIN_VERSION_base(4,9,0)
     120-- Data.Semigroup was added in base-4.9
     121import Data.Semigroup as Sem
     122#endif
     123#if !(MIN_VERSION_base(4,8,0))
     124-- starting with base-4.8, Monoid is rexported from Prelude
     125import Data.Monoid
     126#endif
     127
     128appendFoo :: Foo -> Foo -> Foo
     129appendFoo = …
     130
     131emptyFoo :: Foo
     132emptyFoo = …
     133
     134#if MIN_VERSION_base(4,9,0)
     135instance Sem.Semigroup Foo where
     136  (<>) = appendFoo
     137#endif
     138
     139instance Monoid Foo where
     140  mempty = emptyFoo
     141
     142#if MIN_VERSION_base(4,11,0)
     143-- starting with base-4.11, mappend definitions are redundant;
     144-- at some point `mappend` will be removed from `Monoid`
     145#elif MIN_VERSION_base(4,9,0)
     146  mappend = (Sem.<>)
     147#else // base < 4.9
     148-- prior to GHC 8.0 / base-4.9 where no `Semigroup` class existed
     149  mappend = appendFoo
     150# endif
     151
     152}}}
     153
     154
    112155----
    113156