From 5f621a78217237a4bdfb299b68827da6cc8f357e Mon Sep 17 00:00:00 2001 From: Vladislav Zavialov Date: Fri, 1 May 2020 20:26:45 +0300 Subject: Add Semigroup/Monoid for Q (#18123) --- libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 9 +++++++++ libraries/template-haskell/changelog.md | 2 ++ 2 files changed, 11 insertions(+) (limited to 'libraries') diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index 60fb9d37ca..d994aa686d 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -33,6 +33,7 @@ import Data.IORef import System.IO.Unsafe ( unsafePerformIO ) import Control.Monad (liftM) import Control.Monad.IO.Class (MonadIO (..)) +import Control.Applicative (liftA2) import System.IO ( hPutStrLn, stderr ) import Data.Char ( isAlpha, isAlphaNum, isUpper, ord ) import Data.Int @@ -206,6 +207,14 @@ instance Applicative Q where Q f <*> Q x = Q (f <*> x) Q m *> Q n = Q (m *> n) +-- | @since 2.17.0.0 +instance Semigroup a => Semigroup (Q a) where + (<>) = liftA2 (<>) + +-- | @since 2.17.0.0 +instance Monoid a => Monoid (Q a) where + mempty = pure mempty + ----------------------------------------------------- -- -- The Quote class diff --git a/libraries/template-haskell/changelog.md b/libraries/template-haskell/changelog.md index 55aab10c0d..24a74e4616 100644 --- a/libraries/template-haskell/changelog.md +++ b/libraries/template-haskell/changelog.md @@ -22,6 +22,8 @@ * Fix Show instance for `Bytes`: we were showing the pointer value while we want to show the contents (#16457). + * Add `Semigroup` and `Monoid` instances for `Q` (#18123). + ## 2.16.0.0 *TBA* * Add support for tuple sections. (#15843) The type signatures of `TupE` and -- cgit v1.2.1