on master help sign in
Show that State improves over StateT wrt. exceptions
commita2681ebc95e7f0547a5b20f5b439eb1e774fa9a0 authorAndrzej Rybczak <andrzej@rybczak.net> dateTue 21 Dec 2021, 00:33 (5 years ago) parent4fb7b5f
1 file changed+20
effectful-core/src/Effectful/State/Local.hs+20
effectful-core/src/Effectful/State/Local.hs+20
@@ -5,6 +5,26 @@
55--
66-- - very fast.
77--
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!"
828module Effectful.State.Local
929 ( State
1030 , runState