-
I'm trying to implement a resumeable exception effect but I'm lost. The idea is that For example, if I have a throw like this: i :: Foo <- throw FooDecodingException Then the code cathing the exception can resume the code: catch x (\FooDecodingException -> pure (Resume ...)) or handle it: value <- catch x (\FooDecodingException -> pure (Handled ...)) The problem is I'm not sure how to represent the continuation of data Exception (resumeValue :: Type) (errorValue :: Type) m a where
Throw :: errorValue -> Exception resumeValue errorValue m resumeValue
Catch :: m a -> (errorValue -> m (Resume a resumeValue)) -> Exception resumeValue errorValue m a
type instance DispatchOf (Exception resumeValue errorValue) = Dynamic
data Resume handlerValue resumeValue = HandleError handlerValue | Resume resumeValue
throw :: Exception resumeValue errorValue :> es => errorValue -> Eff es resumeValue
throw = send . Throw
catch ::
forall resumeValue errorValue es a .
Exception resumeValue errorValue :> es =>
Eff es a -> (errorValue -> Eff es (Resume a resumeValue)) -> Eff es a
catch action handler = send (Catch @(Eff es) @a @errorValue @resumeValue action handler) I'm not sure how to capture the continuation in Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No. You can't have access to continuations and MonadUnliftIO instance at the same time (because of functions like Is there any particular reason for you trying to reimplement Error? EDIT: I see your |
Beta Was this translation helpful? Give feedback.
No.
You can't have access to continuations and MonadUnliftIO instance at the same time (because of functions like
bracket
orforkIO
). See this post for more information.Is there any particular reason for you trying to reimplement Error?
EDIT: I see your
Exception
is an amalgamation of Error and Coroutine. But you can't do Couroutine witheffectful
, so yeah, that won't work.