Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type EarlyReturn = Exception
- withEarlyReturn :: forall r (es :: Effects). (forall (er :: Effects). EarlyReturn r er -> Eff (er :& es) r) -> Eff es r
- returnEarly :: forall (er :: Effects) (es :: Effects) r a. er :> es => EarlyReturn r er -> r -> Eff es a
Documentation
Early return allows to define a block from which you can return early. Early return is implemented as an exception, and its API is just an alternate interface to exceptions.
Handle
type EarlyReturn = Exception Source #
Handlers
:: forall r (es :: Effects). (forall (er :: Effects). EarlyReturn r er -> Eff (er :& es) r) | |
-> Eff es r | ͘ |
Run an Eff
action with the ability to return early to this
point. In the language of exceptions, withEarlyReturn
installs
an exception handler for an exception of type r
.
>>> runPureEff $ withEarlyReturn $ \e -> do for_ [1 .. 10] $ \i -> do when (i >= 5) $ returnEarly e ("Returned early with " ++ show i) pure "End of loop" "Returned early with 5"
Effectful operations
:: forall (er :: Effects) (es :: Effects) r a. er :> es | |
=> EarlyReturn r er | |
-> r | Return early to the handler, with this value. |
-> Eff es a |
>>> runPureEff $ withEarlyReturn $ \e -> do for_ [1 .. 10] $ \i -> do when (i >= 5) $ returnEarly e ("Returned early with " ++ show i) pure "End of loop" "Returned early with 5"