Use tryS instead of catchE
This commit is contained in:
parent
33aa149351
commit
fcaef9c3b6
1 changed files with 7 additions and 11 deletions
|
@ -325,19 +325,15 @@ If a control function only takes one action as input, you can get away
|
||||||
without discarding.
|
without discarding.
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
catchE :: Exception e
|
|
||||||
=> ExceptT ex IO a
|
|
||||||
-> (e -> ExceptT ex IO a)
|
|
||||||
-> ExceptT ex IO a
|
|
||||||
catchE (ExceptT f) onErr =
|
|
||||||
ExceptT $ f `catch` (runExceptT . onErr)
|
|
||||||
|
|
||||||
catchS :: Exception e
|
|
||||||
=> StateT s IO a
|
|
||||||
-> (e -> StateT s IO a)
|
|
||||||
-> StateT s IO a
|
|
||||||
catchS (StateT f) onErr = StateT $ \s ->
|
catchS (StateT f) onErr = StateT $ \s ->
|
||||||
f s `catch` (flip runStateT s . onErr)
|
f s `catch` (flip runStateT s . onErr)
|
||||||
|
|
||||||
|
tryS (StateT f) = StateT $ \s -> do
|
||||||
|
eres <- try (f s)
|
||||||
|
return $
|
||||||
|
case eres of
|
||||||
|
Left e -> (Left e, s)
|
||||||
|
Right (a, s') -> (Right a, s')
|
||||||
```
|
```
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
Loading…
Reference in a new issue