@@ -0,0 +1,46 @@
1+module Effectful.Error.Dynamic
12+import Effectful.Handler
13+import Effectful.Monad
14+import qualified Effectful.Error as E
16+data Error e :: Effect where
17+ ThrowError :: e -> Error e m a
18+ CatchError :: m a -> (CallStack -> e -> m a) -> Error e m a
22+ => Eff (Error e : es) a
23+ -> Eff es (Either (CallStack, e) a)
24+runError = reinterpretM E.runError $ \env -> \case
25+ ThrowError e -> E.throwError e
26+ CatchError m h -> localSeqUnlift env $ \run -> do
27+ E.catchError (run m) (\cs -> run . h cs)
30+ :: (HasCallStack, Error e :> es)
33+throwError = send . ThrowError
38+ -> (CallStack -> e -> Eff es a)
40+catchError m = send . CatchError m
45+ -> Eff es (Either (CallStack, e) a)
46+tryError m = (Right <$> m) `catchError` \es e -> pure $ Left (es, e)