rescue-0.2.0: More understandable exceptions

Safe HaskellNone
LanguageHaskell2010

Control.Monad.Rescue

Contents

Description

Rescue semantics & helpers

Essentially a type-directed version of Catch.

This is the opposite of Raise, which embeds en error. Rescue takes a potential error out of the surrounding context and either handles or exposes it.

Synopsis

Documentation

rescue :: (MonadRescue m, RaisesOnly m errs) => m a -> (OpenUnion errs -> m a) -> m a Source #

Handle all exceptions

>>> type MyErrs = '[FooErr, BarErr]
>>> myErrs = Proxy @MyErrs
>>> :{
goesBoom :: Int -> Rescue MyErrs String
goesBoom x =
  if x > 50
    then return (show x)
    else raise FooErr
:}
>>> handler = catchesOpenUnion (\foo -> "Foo: " <> show foo, \bar -> "Bar:" <> show bar)
>>> rescue (goesBoom 42) (pure . handler)
RescueT (Identity (Right "Foo: FooErr"))

reattempt :: MonadRescue m => Natural -> m a -> m a Source #

retry without asynchoronous exception cleanup. Useful when not dealing with external resources that may be dangerous to close suddenly.

onRaise :: (MonadRescue m, RaisesOnly m errs) => (OpenUnion errs -> m ()) -> m a -> m (Result errs a) Source #

lastly :: (Contains (Errors m) (Errors m), MonadRescue m) => m a -> m b -> m a Source #

Run an additional step, and throw away the result. Return the result of the action passed.

Reexports