Safe Haskell | None |
---|---|
Language | Haskell2010 |
The MonadRaise
class, which is an effect for
early escape / happy path programming with an exception side channel
Documentation
class Monad m => MonadRaise m where Source #
Raise semantics, like a type-directed MonadThrow
.
Not unlike MonadError
with an in-built open variant.
raise :: Subset err (ErrorCase m) => err -> m a Source #
Raise an error
The Proxy
gives a type hint to the type checker.
If you have a case where it can be inferred, see raise'
.
Examples
>>>
data FooErr = FooErr deriving Show
>>>
data BarErr = BarErr deriving Show
>>>
data QuuxErr = QuuxErr deriving Show
>>>
>>>
type MyErrs = '[FooErr, BarErr]
>>>
>>>
:{
goesBoom :: Int -> Either (OpenUnion MyErrs) Int goesBoom x = if x > 50 then return x else raise FooErr :}
>>>
goesBoom 42
Left (Identity FooErr)
>>>
:{
maybeBoom :: Int -> Maybe Int maybeBoom x = if x > 50 then return x else raise () :}
>>>
maybeBoom 42
Nothing