HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduleeffectful-core-2.7.1.2GHC2021

Effectful.ReturnWith.Static

Support for early return from a computation.

Example1 expression
import Control.Monad (when)
Example1 expression
:{  classify :: ReturnWith String :> es => Int -> Eff es String  classify n = do    when (n < 0) $ returnWith "negative"    when (n == 0) $ returnWith "zero"    pure "positive":}
Example1 expression
runEff . runReturnWith $ classify 5"positive"
Example1 expression
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.

  • 1 type
  • 2 values

Effect

1 declaration

Handlers

Operations