on master help sign in
Define Semigroup instances and make `-Wcompat`-clean
a0dc18eHerbert Valerio Riedel
Data/Text.hs+15
@@ -214,6 +214,9 @@ import qualified Data.Text.Array as A
214import qualified Data.List as L
214import qualified Data.List as L
215import Data.Binary (Binary(get, put))
215import Data.Binary (Binary(get, put))
216import Data.Monoid (Monoid(..))
216import Data.Monoid (Monoid(..))
217+#if MIN_VERSION_base(4,9,0)
218+import Data.Semigroup (Semigroup(..))
219+#endif
217import Data.String (IsString(..))
220import Data.String (IsString(..))
218import qualified Data.Text.Internal.Fusion as S
221import qualified Data.Text.Internal.Fusion as S
219import qualified Data.Text.Internal.Fusion.Common as S
222import qualified Data.Text.Internal.Fusion.Common as S
@@ -326,9 +329,21 @@ instance Ord Text where
326instance Read Text where
329instance Read Text where
327 readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
330 readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
328
331
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+
329instance Monoid Text where
340instance Monoid Text where
330 mempty = empty
341 mempty = empty
342+#if MIN_VERSION_base(4,9,0)
343+ mappend = (<>) -- future-proof definition
344+#else
331 mappend = append
345 mappend = append
346+#endif
332 mconcat = concat
347 mconcat = concat
333
348
334instance IsString Text where
349instance IsString Text where
Data/Text/Internal/Builder.hs+13
@@ -59,6 +59,9 @@ module Data.Text.Internal.Builder
59
59
60import Control.Monad.ST (ST, runST)
60import Control.Monad.ST (ST, runST)
61import Data.Monoid (Monoid(..))
61import Data.Monoid (Monoid(..))
62+#if MIN_VERSION_base(4,9,0)
63+import Data.Semigroup (Semigroup(..))
64+#endif
62import Data.Text.Internal (Text(..))
65import Data.Text.Internal (Text(..))
63import Data.Text.Internal.Lazy (smallChunkSize)
66import Data.Text.Internal.Lazy (smallChunkSize)
64import Data.Text.Unsafe (inlineInterleaveST)
67import Data.Text.Unsafe (inlineInterleaveST)
@@ -89,10 +92,20 @@ newtype Builder = Builder {
89 -> ST s [S.Text]
92 -> ST s [S.Text]
90 }
93 }
91
94
95+#if MIN_VERSION_base(4,9,0)
96+instance Semigroup Builder where
97+ (<>) = append
98+ {-# INLINE (<>) #-}
99+#endif
100+
92instance Monoid Builder where
101instance Monoid Builder where
93 mempty = empty
102 mempty = empty
94 {-# INLINE mempty #-}
103 {-# INLINE mempty #-}
104+#if MIN_VERSION_base(4,9,0)
105+ mappend = (<>) -- future-proof definition
106+#else
95 mappend = append
107 mappend = append
108+#endif
96 {-# INLINE mappend #-}
109 {-# INLINE mappend #-}
97 mconcat = foldr mappend Data.Monoid.mempty
110 mconcat = foldr mappend Data.Monoid.mempty
98 {-# INLINE mconcat #-}
111 {-# INLINE mconcat #-}
Data/Text/Lazy.hs+15
@@ -214,6 +214,9 @@ import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), constrIndex,
214 Constr, mkConstr, DataType, mkDataType, Fixity(Prefix))
214 Constr, mkConstr, DataType, mkDataType, Fixity(Prefix))
215import Data.Binary (Binary(get, put))
215import Data.Binary (Binary(get, put))
216import Data.Monoid (Monoid(..))
216import Data.Monoid (Monoid(..))
217+#if MIN_VERSION_base(4,9,0)
218+import Data.Semigroup (Semigroup(..))
219+#endif
217import Data.String (IsString(..))
220import Data.String (IsString(..))
218import qualified Data.Text as T
221import qualified Data.Text as T
219import qualified Data.Text.Internal as T
222import qualified Data.Text.Internal as T
@@ -335,9 +338,21 @@ instance Show Text where
335instance Read Text where
338instance Read Text where
336 readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
339 readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
337
340
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+
338instance Monoid Text where
349instance Monoid Text where
339 mempty = empty
350 mempty = empty
351+#if MIN_VERSION_base(4,9,0)
352+ mappend = (<>) -- future-proof definition
353+#else
340 mappend = append
354 mappend = append
355+#endif
341 mconcat = concat
356 mconcat = concat
342
357
343instance IsString Text where
358instance IsString Text where