@@ -3,7 +3,7 @@
3-- - shared between multiple threads (if you want each thead to manage its own
3-- - shared between multiple threads (if you want each thead to manage its own
4-- version of the value, see "Effectful.Writer.Local").
4-- version of the value, see "Effectful.Writer.Local").
6−-- - slower than "Effectful.Writer.Local".
6+-- - slightly slower than "Effectful.Writer.Local".
8-- /Warning:/ 'Writer'\'s state will be accumulated via __left-associated__ uses
8-- /Warning:/ 'Writer'\'s state will be accumulated via __left-associated__ uses
9-- of '<>', which makes it unsuitable for use with types for which such pattern
9-- of '<>', which makes it unsuitable for use with types for which such pattern
@@ -25,7 +25,7 @@ module Effectful.Writer.Shared
27import Control.Concurrent.MVar
27import Control.Concurrent.MVar
28−import Control.Exception
28+import Control.Exception (onException, uninterruptibleMask)
30import Effectful.Dispatch.Static
30import Effectful.Dispatch.Static
31import Effectful.Monad
31import Effectful.Monad
@@ -61,7 +61,18 @@ tell w1 = unsafeEff $ \es -> do
62-- /Note:/ if a runtime exception is received while the action is executed, the
62-- /Note:/ if a runtime exception is received while the action is executed, the
63-- partial output of the action will still be appended to the overall output of
63-- partial output of the action will still be appended to the overall output of
64−-- the 'Writer'.
64+-- the 'Writer':
67+-- runEff . execWriter @String $ do
69+-- handle (\(_::ErrorCall) -> pure ((), "")) $ do
65listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
76listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
66listen m = unsafeEff $ \es -> do
77listen m = unsafeEff $ \es -> do
67 -- The mask is uninterruptible because modifyMVar_ v0 in the merge function
78 -- The mask is uninterruptible because modifyMVar_ v0 in the merge function
@@ -91,3 +102,7 @@ listens :: (Writer w :> es, Monoid w) => (w -> b) -> Eff es a -> Eff es (a, b)
91listens f m = do
102listens f m = do
92 (a, w) <- listen m
103 (a, w) <- listen m
93 pure (a, f w)
104 pure (a, f w)
107+-- >>> import Control.Exception (ErrorCall)
108+-- >>> import Control.Monad.Catch