@@ -24,7 +24,7 @@ module Effectful.Writer.Local
2424 , listens
2525 ) where
2626
27−import Control.Exception
27+import Control.Exception (onException, mask)
2828
2929import Effectful.Dispatch.Static
3030import Effectful.Monad
@@ -57,7 +57,18 @@ tell w = stateEffect $ \(IdA (Writer w0)) -> ((), IdA (Writer (w0 <> w)))
5757--
5858-- /Note:/ if a runtime exception is received while the action is executed, the
5959-- partial output of the action will still be appended to the overall output of
60−-- the 'Writer'.
60+-- the 'Writer':
61+--
62+-- >>> :{
63+-- runEff . execWriter @String $ do
64+-- tell "Hi"
65+-- handle (\(_::ErrorCall) -> pure ((), "")) $ do
66+-- tell " there"
67+-- listen $ do
68+-- tell "!"
69+-- error "oops"
70+-- :}
71+-- "Hi there!"
6172listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
6273listen m = unsafeEff $ \es -> mask $ \restore -> do
6374 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)
7788listens f m = do
7889 (a, w) <- listen m
7990 pure (a, f w)
91+
92+-- $setup
93+-- >>> import Control.Monad.Catch
94+-- >>> import Control.Exception (ErrorCall)