| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Effectful.ReturnWith.Static
Contents
Description
Support for early return from a computation.
>>>import Control.Monad (when)
>>>:{classify :: ReturnWith String :> es => Int -> Eff es String classify n = do when (n < 0) $ returnWith "negative" when (n == 0) $ returnWith "zero" pure "positive" :}
>>>runEff . runReturnWith $ classify 5"positive"
>>>runEff . runReturnWith $ classify (-5)"negative"
Interaction with threads
The ReturnWith effect uses runtime exceptions underneath, so the usual
rules apply. In particular, in multi-threaded code a call to returnWith in
a child thread will not automatically propagate to the parent. If you need
that, use functions such as withAsync from the
Effectful.Concurrent.Async
module of the effectful package (which propagate exceptions from child
threads to their parents) or arrange the propagation yourself.
For more information see the documentation of the Concurrent effect.
Since: 2.7.0.0
Synopsis
- data ReturnWith (r :: Type) :: Effect
- runReturnWith :: forall r es. HasCallStack => Eff (ReturnWith r : es) r -> Eff es r
- returnWith :: forall r es a. (HasCallStack, ReturnWith r :> es) => r -> Eff es a
Effect
data ReturnWith (r :: Type) :: Effect Source #
Provide the ability to return early with a value of type r.
Instances
| type DispatchOf (ReturnWith r) Source # | |
Defined in Effectful.ReturnWith.Static | |
| newtype StaticRep (ReturnWith r) Source # | |
Defined in Effectful.ReturnWith.Static | |
Handlers
runReturnWith :: forall r es. HasCallStack => Eff (ReturnWith r : es) r -> Eff es r Source #
Run a computation that can return early with a value of type r.
Operations
Arguments
| :: forall r es a. (HasCallStack, ReturnWith r :> es) | |
| => r | The value. |
| -> Eff es a |
Return early with the given value.