From b2d59dc0d61639b3c3bd39a9e7100c7d77a06754 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Sat, 6 Jul 2019 10:31:33 -0400 Subject: [PATCH 1/5] Upgrade to fused-effects 0.5. --- fused-effects-exceptions.cabal | 12 +++++++----- src/Control/Effect/Catch.hs | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/fused-effects-exceptions.cabal b/fused-effects-exceptions.cabal index 5a8ecbb..5fe9c22 100644 --- a/fused-effects-exceptions.cabal +++ b/fused-effects-exceptions.cabal @@ -1,5 +1,7 @@ +cabal-version: 2.4 + name: fused-effects-exceptions -version: 0.1.1.0 +version: 0.2.0.0 synopsis: Handle exceptions thrown in IO with fused-effects. description: Provides an effect that enables catching exceptions thrown from impure computations such as 'IO'. homepage: https://github.com/patrickt/fused-effects-exceptions#readme @@ -8,7 +10,7 @@ license-file: LICENSE author: Josh Vera maintainer: patrickt@github.com copyright: 2019 Josh Vera and Patrick Thomson -category: Control. +category: Control build-type: Simple cabal-version: >=1.10 extra-source-files: README.md @@ -19,10 +21,10 @@ library hs-source-dirs: src default-language: Haskell2010 exposed-modules: Control.Effect.Catch - build-depends: base >= 4.7 && < 5 - , fused-effects >= 0.3 && <1 + build-depends: base >= 4.7 && < 5 + , fused-effects ^>= 0.5 , safe-exceptions >= 0.1 && <1 - , unliftio-core >= 0.1.2 && <1 + , unliftio-core >= 0.1.2 && <1 source-repository head type: git diff --git a/src/Control/Effect/Catch.hs b/src/Control/Effect/Catch.hs index e326b36..662a381 100644 --- a/src/Control/Effect/Catch.hs +++ b/src/Control/Effect/Catch.hs @@ -27,12 +27,12 @@ import Control.Monad.IO.Class import Control.Monad.IO.Unlift data Catch m k - = forall output e . Exc.Exception e => CatchIO (m output) (e -> m output) (output -> k) + = forall output e . Exc.Exception e => CatchIO (m output) (e -> m output) (output -> m k) -deriving instance Functor (Catch m) +deriving instance Functor m => Functor (Catch m) instance HFunctor Catch where - hmap f (CatchIO go cleanup k) = CatchIO (f go) (f . cleanup) k + hmap f (CatchIO go cleanup k) = CatchIO (f go) (f . cleanup) (f . k) instance Effect Catch where handle state handler (CatchIO go cleanup k) From 57b1dc8b5deadbe741ce22398d836a14dbba7577 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Sat, 6 Jul 2019 10:38:50 -0400 Subject: [PATCH 2/5] Clean up Cabal detritus. --- fused-effects-exceptions.cabal | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fused-effects-exceptions.cabal b/fused-effects-exceptions.cabal index 5fe9c22..dfa63e8 100644 --- a/fused-effects-exceptions.cabal +++ b/fused-effects-exceptions.cabal @@ -5,14 +5,13 @@ version: 0.2.0.0 synopsis: Handle exceptions thrown in IO with fused-effects. description: Provides an effect that enables catching exceptions thrown from impure computations such as 'IO'. homepage: https://github.com/patrickt/fused-effects-exceptions#readme -license: BSD3 +license: BSD-3-Clause license-file: LICENSE author: Josh Vera maintainer: patrickt@github.com copyright: 2019 Josh Vera and Patrick Thomson category: Control build-type: Simple -cabal-version: >=1.10 extra-source-files: README.md tested-with: GHC == 8.6.4 From 44ff4aeb258ae0dd46361e233779c657870f7b35 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 15 Jul 2019 15:58:06 -0400 Subject: [PATCH 3/5] Fix a URL. --- fused-effects-exceptions.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fused-effects-exceptions.cabal b/fused-effects-exceptions.cabal index dfa63e8..c6cd9c4 100644 --- a/fused-effects-exceptions.cabal +++ b/fused-effects-exceptions.cabal @@ -4,7 +4,7 @@ name: fused-effects-exceptions version: 0.2.0.0 synopsis: Handle exceptions thrown in IO with fused-effects. description: Provides an effect that enables catching exceptions thrown from impure computations such as 'IO'. -homepage: https://github.com/patrickt/fused-effects-exceptions#readme +homepage: https://github.com/fused-effects/fused-effects-exceptions#readme license: BSD-3-Clause license-file: LICENSE author: Josh Vera From 06a867679d3ab366b0de6ad32f5f46337d6923e9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 15 Jul 2019 16:02:09 -0400 Subject: [PATCH 4/5] Rename runCatch to unliftCatch. --- src/Control/Effect/Catch.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Control/Effect/Catch.hs b/src/Control/Effect/Catch.hs index 662a381..4cd5683 100644 --- a/src/Control/Effect/Catch.hs +++ b/src/Control/Effect/Catch.hs @@ -13,7 +13,6 @@ module Control.Effect.Catch ( Catch (..) , catch , catchSync - , runCatch , withCatch , CatchC (..) ) where @@ -63,10 +62,10 @@ catchSync f g = f `catch` \e -> else liftIO (Exc.throw e) -- | Evaluate a 'Catch' effect. -runCatch :: (forall x . m x -> IO x) - -> CatchC m a - -> m a -runCatch handler = runReader (Handler handler) . runCatchC +unliftCatch :: (forall x . m x -> IO x) + -> CatchC m a + -> m a +unliftCatch handler = runReader (Handler handler) . runCatchC -- | Evaluate a 'Catch' effect, using 'MonadUnliftIO' to infer a correct -- unlifting function. @@ -83,7 +82,7 @@ newtype CatchC m a = CatchC { runCatchC :: ReaderC (Handler m) m a } instance MonadUnliftIO m => MonadUnliftIO (CatchC m) where askUnliftIO = CatchC . ReaderC $ \(Handler h) -> - withUnliftIO $ \u -> pure (UnliftIO $ \r -> unliftIO u (runCatch h r)) + withUnliftIO $ \u -> pure (UnliftIO $ \r -> unliftIO u (unliftCatch h r)) instance (Carrier sig m, MonadIO m) => Carrier (Catch :+: sig) (CatchC m) where eff (L (CatchIO act cleanup k)) = do From 073f8199dcd317970c10acf14e208316fdc8503b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 15 Jul 2019 16:02:23 -0400 Subject: [PATCH 5/5] Rename withCatch to runCatch. --- src/Control/Effect/Catch.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Control/Effect/Catch.hs b/src/Control/Effect/Catch.hs index 4cd5683..3bebac4 100644 --- a/src/Control/Effect/Catch.hs +++ b/src/Control/Effect/Catch.hs @@ -13,7 +13,7 @@ module Control.Effect.Catch ( Catch (..) , catch , catchSync - , withCatch + , runCatch , CatchC (..) ) where @@ -69,8 +69,8 @@ unliftCatch handler = runReader (Handler handler) . runCatchC -- | Evaluate a 'Catch' effect, using 'MonadUnliftIO' to infer a correct -- unlifting function. -withCatch :: MonadUnliftIO m => CatchC m a -> m a -withCatch c = withRunInIO (\f -> runHandler (Handler f) c) +runCatch :: MonadUnliftIO m => CatchC m a -> m a +runCatch c = withRunInIO (\f -> runHandler (Handler f) c) newtype Handler m = Handler (forall x . m x -> IO x)