| 114 | === Alternative w/ conditionally defined `Semigroup` instance & -XCPP |

| 115 | |

| 116 | This 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 |

| 121 | import 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 |

| 125 | import Data.Monoid |

| 126 | #endif |

| 127 | |

| 128 | appendFoo :: Foo -> Foo -> Foo |

| 129 | appendFoo = … |

| 130 | |

| 131 | emptyFoo :: Foo |

| 132 | emptyFoo = … |

| 133 | |

| 134 | #if MIN_VERSION_base(4,9,0) |

| 135 | instance Sem.Semigroup Foo where |

| 136 | (<>) = appendFoo |

| 137 | #endif |

| 138 | |

| 139 | instance 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 | |