th-orphans 0.13.10 → 0.13.11
raw patch · 3 files changed
+75/−9 lines, 3 filesdep +semigroupsdep +th-compatdep ~template-haskellPVP ok
version bump matches the API change (PVP)
Dependencies added: semigroups, th-compat
Dependency ranges changed: template-haskell
API changes (from Hackage documentation)
+ Language.Haskell.TH.Instances: instance (Language.Haskell.TH.Syntax.Compat.Quote m, GHC.Base.Monoid w) => Language.Haskell.TH.Syntax.Compat.Quote (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
+ Language.Haskell.TH.Instances: instance (Language.Haskell.TH.Syntax.Compat.Quote m, GHC.Base.Monoid w) => Language.Haskell.TH.Syntax.Compat.Quote (Control.Monad.Trans.Writer.Lazy.WriterT w m)
+ Language.Haskell.TH.Instances: instance Control.Monad.Fix.MonadFix Language.Haskell.TH.Syntax.Q
+ Language.Haskell.TH.Instances: instance GHC.Base.Monoid a => GHC.Base.Monoid (Language.Haskell.TH.Syntax.Q a)
+ Language.Haskell.TH.Instances: instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Language.Haskell.TH.Syntax.Q a)
+ Language.Haskell.TH.Instances: instance Language.Haskell.TH.Syntax.Compat.Quote m => Language.Haskell.TH.Syntax.Compat.Quote (Control.Monad.Trans.Reader.ReaderT r m)
+ Language.Haskell.TH.Instances: instance Language.Haskell.TH.Syntax.Compat.Quote m => Language.Haskell.TH.Syntax.Compat.Quote (Control.Monad.Trans.State.Lazy.StateT s m)
Files
- CHANGELOG.md +9/−0
- src/Language/Haskell/TH/Instances.hs +57/−4
- th-orphans.cabal +9/−5
CHANGELOG.md view
@@ -1,3 +1,12 @@+### 0.13.11 [2020.09.29]+* Allow building with `template-haskell-2.17.0.0` (GHC 9.0).+* Define `Quote` instances for `ReaderT`, `StateT`, `WriterT`, and `RWST`. In+ order to define these instances on as many versions of `template-haskell` as+ possible, this library now depends on the `th-compat` library, which+ backports the `Quote` class to older versions of `template-haskell`.+* Backport the `Semigroup`, `Monoid`, and `MonadFix` instances for `Q` that+ were introduced in `template-haskell-2.17.0.0`.+ ### 0.13.10 [2020.04.13] * Implement `liftTyped` in the `Lift Bytes` instance.
src/Language/Haskell/TH/Instances.hs view
@@ -57,15 +57,17 @@ -- collisions of orphans between @th-orphans@ and @th-lift-instances@. module Language.Haskell.TH.Instances () where -import Language.Haskell.TH+import Language.Haskell.TH hiding (newName) import Language.Haskell.TH.Instances.Internal import Language.Haskell.TH.Lift (deriveLiftMany) import Language.Haskell.TH.ReifyMany-import Language.Haskell.TH.Syntax+import Language.Haskell.TH.Syntax hiding (newName)+import Language.Haskell.TH.Syntax.Compat (Quote(..)) import Control.Monad.Reader (ReaderT(ReaderT), runReaderT) import Control.Monad.RWS (RWST(RWST), runRWST) import Control.Monad.State (StateT(StateT), runStateT)+import qualified Control.Monad.Trans as Trans (MonadTrans(lift)) import Control.Monad.Writer (WriterT(WriterT), runWriterT) import Instances.TH.Lift () @@ -97,7 +99,7 @@ # endif # if !(MIN_VERSION_base(4,8,0))-import Data.Monoid (Monoid)+import Data.Monoid (Monoid (..)) # endif # if MIN_VERSION_template_haskell(2,3,0) && defined(LANGUAGE_DeriveDataTypeable)@@ -120,9 +122,24 @@ #if MIN_VERSION_template_haskell(2,16,0) import GHC.Ptr (Ptr(Ptr)) import GHC.ForeignPtr (newForeignPtr_)+import Language.Haskell.TH.Syntax.Compat (liftTypedFromUntypedSplice) import System.IO.Unsafe (unsafePerformIO) #endif +#if !MIN_VERSION_template_haskell(2,17,0)+import Control.Applicative (liftA2)+import Control.Concurrent.MVar (newEmptyMVar, putMVar, readMVar)+import Control.Monad.Fix (MonadFix (..))+import System.IO.Unsafe (unsafeInterleaveIO)++import qualified Data.Semigroup as Semi++# if MIN_VERSION_base(4,11,0)+import Control.Exception (throwIO, catch)+import GHC.IO.Exception (BlockedIndefinitelyOnMVar (..), FixIOException (..))+# endif+#endif+ #if !MIN_VERSION_template_haskell(2,11,0) deriving instance Show NameFlavour deriving instance Show NameSpace@@ -386,18 +403,26 @@ deriving instance Bounded Extension #endif +instance Quote m => Quote (ReaderT r m) where+ newName = Trans.lift . newName $(deriveQuasiTrans [t| forall r m. Quasi m => Proxy2 (ReaderT r m) |] [e| \m1 m2 -> ReaderT $ \ r -> runReaderT m1 r `qRecover` runReaderT m2 r |]) +instance (Quote m, Monoid w) => Quote (WriterT w m) where+ newName = Trans.lift . newName $(deriveQuasiTrans [t| forall w m. (Quasi m, Monoid w) => Proxy2 (WriterT w m) |] [e| \m1 m2 -> WriterT $ runWriterT m1 `qRecover` runWriterT m2 |]) +instance Quote m => Quote (StateT s m) where+ newName = Trans.lift . newName $(deriveQuasiTrans [t| forall s m. Quasi m => Proxy2 (StateT s m) |] [e| \m1 m2 -> StateT $ \ s -> runStateT m1 s `qRecover` runStateT m2 s |]) +instance (Quote m, Monoid w) => Quote (RWST r w s m) where+ newName = Trans.lift . newName $(deriveQuasiTrans [t| forall r w s m. (Quasi m, Monoid w) => Proxy2 (RWST r w s m) |] [e| \m1 m2 -> RWST $ \ r s -> runRWST m1 r s `qRecover` runRWST m2 r s |])@@ -419,7 +444,35 @@ |] where size = bytesSize bytes- liftTyped = unsafeTExpCoerce . lift+ liftTyped = liftTypedFromUntypedSplice+#endif++#if !MIN_VERSION_template_haskell(2,17,0)+instance Semi.Semigroup a => Semi.Semigroup (Q a) where+ (<>) = liftA2 (Semi.<>)++instance Monoid a => Monoid (Q a) where+ mempty = return mempty+#if !MIN_VERSION_base(4,11,0)+ mappend = liftA2 mappend+#endif++-- | If the function passed to 'mfix' inspects its argument,+-- the resulting action will throw a 'FixIOException'+-- (@base >=4.11@) or a 'BlockedIndefinitelyOnMVar'+-- with older @base@.+--+instance MonadFix Q where+ mfix k = do+ m <- runIO newEmptyMVar+ ans <- runIO (unsafeInterleaveIO (readMVar m+#if MIN_VERSION_base(4,11,0)+ `catch` \BlockedIndefinitelyOnMVar -> throwIO FixIOException+#endif+ ))+ result <- k ans+ runIO (putMVar m result)+ return result #endif $(reifyManyWithoutInstances ''Lift [''Info, ''Loc] (const True) >>=
th-orphans.cabal view
@@ -1,5 +1,5 @@ name: th-orphans-version: 0.13.10+version: 0.13.11 cabal-version: >= 1.10 build-type: Simple license: BSD3@@ -20,8 +20,8 @@ , GHC == 8.2.2 , GHC == 8.4.4 , GHC == 8.6.5- , GHC == 8.8.1- , GHC == 8.10.1+ , GHC == 8.8.4+ , GHC == 8.10.2 synopsis: Orphan instances for TH datatypes description: Orphan instances for TH datatypes. In particular, instances for Ord and Lift, as well as a few missing Show / Eq. These@@ -31,7 +31,8 @@ library build-depends: base >= 4.3 && < 5,- template-haskell < 2.17,+ template-haskell < 2.18,+ th-compat >= 0.1 && < 0.2, -- https://github.com/mboes/th-lift/issues/14 th-lift >= 0.7.1, th-reify-many >= 0.1 && < 0.2,@@ -39,7 +40,8 @@ mtl if !impl(ghc >= 8.0)- build-depends: fail == 4.9.*+ build-depends: fail == 4.9.*,+ semigroups >= 0.18.5 && < 0.20 -- Use TH to derive Generics instances instead of DeriveGeneric, for < 7.10 if impl(ghc < 7.10)@@ -51,6 +53,8 @@ hs-source-dirs: src ghc-options: -Wall+ if impl(ghc >= 8.6)+ ghc-options: -Wno-star-is-type exposed-modules: Language.Haskell.TH.Instances other-modules: Language.Haskell.TH.Instances.Internal default-language: Haskell2010