on master help sign in
Define Semigroup instances and make `-Wcompat`-clean

See also https://github.com/ekmett/semigroups/issues/56 for the larger picture

commita0dc18efb2174a16811a68f1c4781c9deef40725 authorHerbert Valerio Riedel <hvr@gnu.org> dateMon 21 Dec 2015, 10:12 (11 years ago) parent620a3af
3 files changed+43
Data/Text.hs+15 Data/Text/Internal/Builder.hs+13 Data/Text/Lazy.hs+15
Data/Text.hs+15
@@ -214,6 +214,9 @@ import qualified Data.Text.Array as A
214214import qualified Data.List as L
215215import Data.Binary (Binary(get, put))
216216import Data.Monoid (Monoid(..))
217+#if MIN_VERSION_base(4,9,0)
218+import Data.Semigroup (Semigroup(..))
219+#endif
217220import Data.String (IsString(..))
218221import qualified Data.Text.Internal.Fusion as S
219222import qualified Data.Text.Internal.Fusion.Common as S
@@ -326,9 +329,21 @@ instance Ord Text where
326329instance Read Text where
327330 readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
328331
332+#if MIN_VERSION_base(4,9,0)
333+-- Semigroup orphan instances for older GHCs are provided by
334+-- 'semigroups` package
335+
336+instance Semigroup Text where
337+ (<>) = append
338+#endif
339+
329340instance Monoid Text where
330341 mempty = empty
342+#if MIN_VERSION_base(4,9,0)
343+ mappend = (<>) -- future-proof definition
344+#else
331345 mappend = append
346+#endif
332347 mconcat = concat
333348
334349instance IsString Text where
Data/Text/Internal/Builder.hs+13
@@ -59,6 +59,9 @@ module Data.Text.Internal.Builder
5959
6060import Control.Monad.ST (ST, runST)
6161import Data.Monoid (Monoid(..))
62+#if MIN_VERSION_base(4,9,0)
63+import Data.Semigroup (Semigroup(..))
64+#endif
6265import Data.Text.Internal (Text(..))
6366import Data.Text.Internal.Lazy (smallChunkSize)
6467import Data.Text.Unsafe (inlineInterleaveST)
@@ -89,10 +92,20 @@ newtype Builder = Builder {
8992 -> ST s [S.Text]
9093 }
9194
95+#if MIN_VERSION_base(4,9,0)
96+instance Semigroup Builder where
97+ (<>) = append
98+ {-# INLINE (<>) #-}
99+#endif
100+
92101instance Monoid Builder where
93102 mempty = empty
94103 {-# INLINE mempty #-}
104+#if MIN_VERSION_base(4,9,0)
105+ mappend = (<>) -- future-proof definition
106+#else
95107 mappend = append
108+#endif
96109 {-# INLINE mappend #-}
97110 mconcat = foldr mappend Data.Monoid.mempty
98111 {-# INLINE mconcat #-}
Data/Text/Lazy.hs+15
@@ -214,6 +214,9 @@ import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), constrIndex,
214214 Constr, mkConstr, DataType, mkDataType, Fixity(Prefix))
215215import Data.Binary (Binary(get, put))
216216import Data.Monoid (Monoid(..))
217+#if MIN_VERSION_base(4,9,0)
218+import Data.Semigroup (Semigroup(..))
219+#endif
217220import Data.String (IsString(..))
218221import qualified Data.Text as T
219222import qualified Data.Text.Internal as T
@@ -335,9 +338,21 @@ instance Show Text where
335338instance Read Text where
336339 readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
337340
341+#if MIN_VERSION_base(4,9,0)
342+-- Semigroup orphan instances for older GHCs are provided by
343+-- 'semigroups` package
344+
345+instance Semigroup Text where
346+ (<>) = append
347+#endif
348+
338349instance Monoid Text where
339350 mempty = empty
351+#if MIN_VERSION_base(4,9,0)
352+ mappend = (<>) -- future-proof definition
353+#else
340354 mappend = append
355+#endif
341356 mconcat = concat
342357
343358instance IsString Text where