@@ -24,7 +24,7 @@ module Effectful.Writer.Local
27−import Control.Exception
27+import Control.Exception (onException, mask)
29import Effectful.Dispatch.Static
29import Effectful.Dispatch.Static
30import Effectful.Monad
30import Effectful.Monad
@@ -57,7 +57,18 @@ tell w = stateEffect $ \(IdA (Writer w0)) -> ((), IdA (Writer (w0 <> w)))
58-- /Note:/ if a runtime exception is received while the action is executed, the
58-- /Note:/ if a runtime exception is received while the action is executed, the
59-- partial output of the action will still be appended to the overall output of
59-- partial output of the action will still be appended to the overall output of
60−-- the 'Writer'.
60+-- the 'Writer':
63+-- runEff . execWriter @String $ do
65+-- handle (\(_::ErrorCall) -> pure ((), "")) $ do
61listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
72listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
62listen m = unsafeEff $ \es -> mask $ \restore -> do
73listen m = unsafeEff $ \es -> mask $ \restore -> do
63 w0 <- stateEnv es $ \(IdA (Writer w)) -> (w, IdA (Writer mempty))
74 w0 <- stateEnv es $ \(IdA (Writer w)) -> (w, IdA (Writer mempty))
@@ -77,3 +88,7 @@ listens :: (Writer w :> es, Monoid w) => (w -> b) -> Eff es a -> Eff es (a, b)
77listens f m = do
88listens f m = do
78 (a, w) <- listen m
89 (a, w) <- listen m
79 pure (a, f w)
90 pure (a, f w)
93+-- >>> import Control.Monad.Catch
94+-- >>> import Control.Exception (ErrorCall)