From 1cecebeae770f330b58acaa079defad7ac23e87a Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Sat, 17 Dec 2022 18:37:06 +0200 Subject: [PATCH] MonadTrans has quantified constraint, let's use it --- .github/workflows/haskell-ci.yml | 50 +++--------------------------- cabal.haskell-ci | 2 ++ monad-control.cabal | 20 ++++-------- src/Control/Monad/Trans/Control.hs | 16 +++++----- 4 files changed, 21 insertions(+), 67 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 870c3c2..5fdf7ec 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.15.20220826 +# version: 0.15.20221107 # -# REGENDATA ("0.15.20220826",["github","cabal.project"]) +# REGENDATA ("0.15.20221107",["github","cabal.project"]) # name: Haskell-CI on: @@ -57,46 +57,6 @@ jobs: compilerVersion: 8.8.4 setup-method: hvr-ppa allow-failure: false - - compiler: ghc-8.6.5 - compilerKind: ghc - compilerVersion: 8.6.5 - setup-method: hvr-ppa - allow-failure: false - - compiler: ghc-8.4.4 - compilerKind: ghc - compilerVersion: 8.4.4 - setup-method: hvr-ppa - allow-failure: false - - compiler: ghc-8.2.2 - compilerKind: ghc - compilerVersion: 8.2.2 - setup-method: hvr-ppa - allow-failure: false - - compiler: ghc-8.0.2 - compilerKind: ghc - compilerVersion: 8.0.2 - setup-method: hvr-ppa - allow-failure: false - - compiler: ghc-7.10.3 - compilerKind: ghc - compilerVersion: 7.10.3 - setup-method: hvr-ppa - allow-failure: false - - compiler: ghc-7.8.4 - compilerKind: ghc - compilerVersion: 7.8.4 - setup-method: hvr-ppa - allow-failure: false - - compiler: ghc-7.6.3 - compilerKind: ghc - compilerVersion: 7.6.3 - setup-method: hvr-ppa - allow-failure: false - - compiler: ghc-7.4.2 - compilerKind: ghc - compilerVersion: 7.4.2 - setup-method: hvr-ppa - allow-failure: false fail-fast: false steps: - name: apt @@ -223,11 +183,11 @@ jobs: touch cabal.project touch cabal.project.local echo "packages: ${PKGDIR_monad_control}" >> cabal.project - if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package monad-control" >> cabal.project ; fi - if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi + echo "package monad-control" >> cabal.project + echo " ghc-options: -Werror=missing-methods" >> cabal.project cat >> cabal.project <> cabal.project.local + $HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(monad-control|transformers)$/; }' >> cabal.project.local cat cabal.project cat cabal.project.local - name: dump install plan diff --git a/cabal.haskell-ci b/cabal.haskell-ci index e1f1b77..d1e4c55 100644 --- a/cabal.haskell-ci +++ b/cabal.haskell-ci @@ -1 +1,3 @@ branches: master + +installed: +all -transformers diff --git a/monad-control.cabal b/monad-control.cabal index c2e9a4b..54b92bd 100644 --- a/monad-control.cabal +++ b/monad-control.cabal @@ -37,15 +37,7 @@ extra-source-files: README.markdown tested-with: - GHC ==7.4.2 - || ==7.6.3 - || ==7.8.4 - || ==7.10.3 - || ==8.0.2 - || ==8.2.2 - || ==8.4.4 - || ==8.6.5 - || ==8.8.4 + GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.4 @@ -65,8 +57,8 @@ library ghc-options: -Wall exposed-modules: Control.Monad.Trans.Control build-depends: - base >=4.5 && <5 - , stm >=2.3 && <2.6 - , transformers >=0.2 && <0.7 - , transformers-base >=0.4.6 && <0.5 - , transformers-compat >=0.6.1 && <0.8 + base >=4.13 && <5 + , stm >=2.5.0.0 && <2.6 + , transformers >=0.6.0.0 && <0.7 + , transformers-base >=0.4.6 && <0.5 +-- , transformers-compat >=0.6.1 && <0.8 diff --git a/src/Control/Monad/Trans/Control.hs b/src/Control/Monad/Trans/Control.hs index 345a6b8..5acb462 100644 --- a/src/Control/Monad/Trans/Control.hs +++ b/src/Control/Monad/Trans/Control.hs @@ -172,7 +172,7 @@ import Control.Monad.Base ( MonadBase ) -- @'MonadTransControl'@ allows us to do this: -- -- @ --- withFileLifted' :: (Monad (t IO), MonadTransControl t) => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r +-- withFileLifted' :: MonadTransControl t => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r -- withFileLifted' file mode action = liftWith (\\run -> withFile file mode (run . action)) >>= restoreT . return -- @ class MonadTrans t => MonadTransControl t where @@ -222,7 +222,7 @@ class MonadTrans t => MonadTransControl t where -- @n@ (for all @n@) on the captured state, e.g. -- -- @ - -- withFileLifted :: (Monad (t IO), MonadTransControl t) => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r + -- withFileLifted :: MonadTransControl t => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r -- withFileLifted file mode action = liftWith (\\run -> withFile file mode (run . action)) >>= restoreT . return -- @ -- @@ -382,10 +382,10 @@ defaultRestoreT t = t . restoreT -- | A function like 'Run' that runs a monad transformer @t@ which wraps the -- monad transformers @n@ and @n'@. This is used in 'defaultLiftWith2'. -type RunDefault2 t n n' = forall m b. (Monad m, Monad (n' m)) => t m b -> m (StT n' (StT n b)) +type RunDefault2 t n n' = forall m b. Monad m => t m b -> m (StT n' (StT n b)) -- | Default definition for the 'liftWith' method. -defaultLiftWith2 :: (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n') +defaultLiftWith2 :: (Monad m, MonadTransControl n, MonadTransControl n') => (forall b. n (n' m) b -> t m b) -- ^ Monad constructor -> (forall o b. t o b -> n (n' o) b) -- ^ Monad deconstructor -> (RunDefault2 t n n' -> m a) @@ -394,7 +394,7 @@ defaultLiftWith2 t unT = \f -> t $ liftWith $ \run -> liftWith $ \run' -> f $ ru {-# INLINABLE defaultLiftWith2 #-} -- | Default definition for the 'restoreT' method for double 'MonadTransControl'. -defaultRestoreT2 :: (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n') +defaultRestoreT2 :: (Monad m, MonadTransControl n, MonadTransControl n') => (n (n' m) a -> t m a) -- ^ Monad constructor -> m (StT n' (StT n a)) -> t m a @@ -767,7 +767,7 @@ control f = liftBaseWith f >>= restoreM -- | Lift a computation and restore the monadic state immediately: -- @controlT f = 'liftWith' f >>= 'restoreT' . return@. -controlT :: (MonadTransControl t, Monad (t m), Monad m) +controlT :: (MonadTransControl t, Monad m) => (Run t -> m (StT t a)) -> t m a controlT f = liftWith f >>= restoreT . return {-# INLINABLE controlT #-} @@ -785,7 +785,7 @@ embed_ f = liftBaseWith $ \runInBase -> return (void . runInBase . f) {-# INLINABLE embed_ #-} -- | Capture the current state of a transformer -captureT :: (MonadTransControl t, Monad (t m), Monad m) => t m (StT t ()) +captureT :: (MonadTransControl t, Monad m) => t m (StT t ()) captureT = liftWith $ \runInM -> runInM (return ()) {-# INLINABLE captureT #-} @@ -874,7 +874,7 @@ liftBaseOpDiscard f g = liftBaseWith $ \runInBase -> f $ void . runInBase . g -- | Transform an action in @t m@ using a transformer that operates on the underlying monad @m@ liftThrough - :: (MonadTransControl t, Monad (t m), Monad m) + :: (MonadTransControl t, Monad m) => (m (StT t a) -> m (StT t b)) -- ^ -> t m a -> t m b liftThrough f t = do