Safe Haskell | None |
---|---|
Language | Haskell2010 |
The MonadRescue
class, meant for retrieving the success/failure branches
Synopsis
- class MonadRaise m => MonadRescue m where
Documentation
class MonadRaise m => MonadRescue m where Source #
Pull a potential error out of the surrounding context
NOTE that the target m
may not even be aware of Raise/Rescue. It's an escape to the "normal" world
attempt :: m a -> m (Either (ErrorCase m) a) Source #
Attempt some action, exposing the success and error branches
Examples
>>>
:{
goesBoom :: Int -> Rescue '[FooErr, BarErr] Int goesBoom x = if x > 50 then return x else raise FooErr :}
>>>
runRescue . attempt $ goesBoom 42
Right (Left (Identity FooErr))
Where Identity fooErr
is the selection of the OpenUnion
.
In practice you would handle the OpenUnion
like so:
>>>
let handleErr = catchesOpenUnion (show, show)
>>>
let x = attempt (goesBoom 42) >>= pure . either handleErr show
>>>
runRescue x
Right "FooErr"
Where Identity FooErr
is the selection of the OpenUnion
.