fused-effects-exceptions 0.1.0.0 → 0.1.1.0
raw patch · 2 files changed
+14/−2 lines, 2 filesdep +unliftio-coredep ~fused-effectsPVP ok
version bump matches the API change (PVP)
Dependencies added: unliftio-core
Dependency ranges changed: fused-effects
API changes (from Hackage documentation)
+ Control.Effect.Catch: instance Control.Monad.IO.Unlift.MonadUnliftIO m => Control.Monad.IO.Unlift.MonadUnliftIO (Control.Effect.Catch.CatchC m)
+ Control.Effect.Catch: withCatch :: MonadUnliftIO m => CatchC m a -> m a
Files
fused-effects-exceptions.cabal view
@@ -1,5 +1,5 @@ name: fused-effects-exceptions-version: 0.1.0.0+version: 0.1.1.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@@ -22,6 +22,7 @@ build-depends: base >= 4.7 && < 5 , fused-effects >= 0.3 && <1 , safe-exceptions >= 0.1 && <1+ , unliftio-core >= 0.1.2 && <1 source-repository head type: git
src/Control/Effect/Catch.hs view
@@ -14,6 +14,7 @@ , catch , catchSync , runCatch+ , withCatch , CatchC (..) ) where @@ -23,6 +24,7 @@ import qualified Control.Exception as Exc import Control.Exception.Safe (isSyncException) 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)@@ -60,12 +62,17 @@ -- since we want to preserve async behavior else liftIO (Exc.throw e) --- | Evaulate a 'Catch' effect.+-- | Evaluate a 'Catch' effect. runCatch :: (forall x . m x -> IO x) -> CatchC m a -> m a runCatch 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)+ newtype Handler m = Handler (forall x . m x -> IO x) runHandler :: Handler m -> CatchC m a -> IO a@@ -73,6 +80,10 @@ newtype CatchC m a = CatchC { runCatchC :: ReaderC (Handler m) m a } deriving (Functor, Applicative, Monad, MonadIO)++instance MonadUnliftIO m => MonadUnliftIO (CatchC m) where+ askUnliftIO = CatchC . ReaderC $ \(Handler h) ->+ withUnliftIO $ \u -> pure (UnliftIO $ \r -> unliftIO u (runCatch h r)) instance (Carrier sig m, MonadIO m) => Carrier (Catch :+: sig) (CatchC m) where eff (L (CatchIO act cleanup k)) = do