on master help sign in
Show that State improves over StateT wrt. exceptions
a2681ebAndrzej Rybczak
effectful-core/src/Effectful/State/Local.hs+20
@@ -5,6 +5,26 @@
5--
5--
6-- - very fast.
6-- - very fast.
7--
7--
8+-- /Note:/ unlike 'Control.Monad.Trans.State.StateT', the 'State' effect doesn't
9+-- lose state modifications in presence of runtime exceptions:
10+--
11+-- >>> import Control.Exception (ErrorCall)
12+-- >>> import Control.Monad.Catch
13+--
14+-- >>> import qualified Control.Monad.Trans.State.Strict as S
15+-- >>> :{
16+-- (`S.execStateT` "Hi") . handle (\(_::ErrorCall) -> pure ()) $ do
17+-- S.modify (++ " there!")
18+-- error "oops"
19+-- :}
20+-- "Hi"
21+--
22+-- >>> :{
23+-- runEff . execState "Hi" . handle (\(_::ErrorCall) -> pure ()) $ do
24+-- modify (++ " there!")
25+-- error "oops"
26+-- :}
27+-- "Hi there!"
8module Effectful.State.Local
28module Effectful.State.Local
9 ( State
29 ( State
10 , runState
30 , runState