-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Effectful.Exception module with appropriate re-exports
- Loading branch information
Showing
13 changed files
with
163 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
-- | The 'Eff' monad comes with instances of 'MonadThrow', 'MonadCatch' and | ||
-- 'MonadMask' from the | ||
-- [@exceptions@](https://hackage.haskell.org/package/exceptions) library out of | ||
-- the box, so this module simply re-exports the interface of the | ||
-- [@safe-exceptions@](https://hackage.haskell.org/package/safe-exceptions) | ||
-- library. | ||
-- | ||
-- Why @safe-exceptions@ and not @exceptions@? Because the latter provides more | ||
-- convenience functions and makes it much easier to correctly deal with | ||
-- asynchronous exceptions (for more information see its | ||
-- [README](https://github.com/fpco/safe-exceptions#readme)). | ||
module Effectful.Exception | ||
( C.MonadThrow(..) | ||
, C.MonadCatch(..) | ||
, C.MonadMask(..) | ||
, C.ExitCase(..) | ||
|
||
-- * Utilities | ||
|
||
-- ** Throwing | ||
, Safe.throwString | ||
, Safe.StringException(..) | ||
|
||
-- ** Catching (with recovery) | ||
, Safe.catchIO | ||
, Safe.catchIOError | ||
, Safe.catchAny | ||
, Safe.catchDeep | ||
, Safe.catchAnyDeep | ||
, Safe.catchAsync | ||
, Safe.catchJust | ||
|
||
, Safe.handle | ||
, Safe.handleIO | ||
, Safe.handleIOError | ||
, Safe.handleAny | ||
, Safe.handleDeep | ||
, Safe.handleAnyDeep | ||
, Safe.handleAsync | ||
, Safe.handleJust | ||
|
||
, Safe.try | ||
, Safe.tryIO | ||
, Safe.tryAny | ||
, Safe.tryDeep | ||
, Safe.tryAnyDeep | ||
, Safe.tryAsync | ||
, Safe.tryJust | ||
|
||
, Safe.Handler(..) | ||
, Safe.catches | ||
, Safe.catchesDeep | ||
, Safe.catchesAsync | ||
|
||
-- ** Cleanup (no recovery) | ||
, Safe.onException | ||
, Safe.bracket | ||
, Safe.bracket_ | ||
, Safe.finally | ||
, Safe.withException | ||
, Safe.bracketOnError | ||
, Safe.bracketOnError_ | ||
, Safe.bracketWithError | ||
|
||
-- ** Coercion to sync and async | ||
, Safe.SyncExceptionWrapper(..) | ||
, Safe.toSyncException | ||
, Safe.AsyncExceptionWrapper(..) | ||
, Safe.toAsyncException | ||
|
||
-- ** Check exception type | ||
, Safe.isSyncException | ||
, Safe.isAsyncException | ||
|
||
-- ** Evaluation | ||
, evaluate | ||
, evaluateDeep | ||
|
||
-- * Re-exports from "Control.Exception" | ||
|
||
-- ** The 'SomeException' type | ||
, E.SomeException(..) | ||
|
||
-- ** The 'Exception' class | ||
, E.Exception(..) | ||
|
||
-- ** Concrete exception types | ||
, E.IOException | ||
, E.ArithException(..) | ||
, E.ArrayException(..) | ||
, E.AssertionFailed(..) | ||
, E.NoMethodError(..) | ||
, E.PatternMatchFail(..) | ||
, E.RecConError(..) | ||
, E.RecSelError(..) | ||
, E.RecUpdError(..) | ||
, E.ErrorCall(..) | ||
, E.TypeError(..) | ||
|
||
-- ** Asynchronous exceptions | ||
, E.SomeAsyncException(..) | ||
, E.AsyncException(..) | ||
, E.asyncExceptionToException | ||
, E.asyncExceptionFromException | ||
, E.NonTermination(..) | ||
, E.NestedAtomically(..) | ||
, E.BlockedIndefinitelyOnMVar(..) | ||
, E.BlockedIndefinitelyOnSTM(..) | ||
, E.AllocationLimitExceeded(..) | ||
, E.CompactionFailed(..) | ||
, E.Deadlock(..) | ||
|
||
-- ** Assertions | ||
, E.assert | ||
) where | ||
|
||
import Control.DeepSeq | ||
import Control.Exception qualified as E | ||
import Control.Exception.Safe qualified as Safe | ||
import Control.Monad.Catch qualified as C | ||
|
||
import Effectful | ||
import Effectful.Dispatch.Static | ||
|
||
-- | Lifted version of 'E.evaluate'. | ||
evaluate :: a -> Eff es a | ||
evaluate = unsafeEff_ . E.evaluate | ||
|
||
-- | Deeply evaluate a value using 'evaluate' and 'NFData'. | ||
evaluateDeep :: NFData a => a -> Eff es a | ||
evaluateDeep = unsafeEff_ . E.evaluate . force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters