implement `catchDynE` to catch errors without losing the other effects state
srghma opened this issue · comments
I didnt find this function in https://hackage.haskell.org/package/freer
but it was in a paper "Freer Monads, More Extensible Effects" http://okmij.org/ftp/Haskell/extensible/more.pdf
it allows catching IO exceptions in the presence of other effects
current behaviour is
main = do
(result :: Either Error Unit) <- Run.runBaseEffect $ runExcept $ do
Run.catch (errorHander) (Run.liftEffect $ throwError $ error "asdf")
traceM { result }
will throw runtime error "asdf" and the { result }
is not printed
expected: replace Run.catch
with Run.catchDynE
and catch the js error, print { result }
and finish without error code
another example
output <- runEffect $ runWriter "" do
write "1"
catchDynE (\e -> write "error catched") do
write "2"
liftEffect $ throw $ error "myerror"
write "3"
write "4"
output `shouldEqual` "12error catched4"
I think some kind of function like this is useful, but what do you expect the type signature to be? Exceptions in PureScript and exceptions in Haskell are not the same.
Is this better handled at the lift layer?
liftAff' = rethrow <=< liftAff <<< attempt