concurrent-state 0.2.0.0 → 0.3.0.0
raw patch · 3 files changed
+33/−3 lines, 3 files
Files
- concurrent-state.cabal +1/−1
- src/Control/Monad/State/Concurrent/Lazy.hs +16/−1
- src/Control/Monad/State/Concurrent/Strict.hs +16/−1
concurrent-state.cabal view
@@ -1,5 +1,5 @@ name: concurrent-state-version: 0.2.0.0+version: 0.3.0.0 synopsis: MTL-like library using TVars description: State and Writer backed by TVars. homepage: https://github.com/joelteon/concurrent-state
src/Control/Monad/State/Concurrent/Lazy.hs view
@@ -19,6 +19,9 @@ -- *** The StateC monad transformer StateC, + -- *** Specializations of MonadState operations+ modify,+ -- *** Concurrent state operations runStateC, evalStateC, execStateC, @@ -29,7 +32,7 @@ import Control.Applicative import Control.Concurrent.STM import Control.Monad-import Control.Monad.State+import Control.Monad.State hiding (modify) -- --------------------------------------------------------------------------- -- | A concurrent state transformer monad parameterized by:@@ -88,6 +91,18 @@ liftIO i = StateC $ \s -> do a <- liftIO i return (a, s)++-- | Monadic state transformer. Maps an old state to a new state inside+-- a state monad. The old state is thrown away.+--+-- This is provided because "Control.Monad.State"'s modify function is+-- defined in terms of 'get' and 'put', which results in two STM actions+-- for every modify. Instead, 'modify' can be specialized as a call to+-- 'modifyTVar'.+modify :: MonadIO m => (s -> s) -> StateC s m ()+modify s = StateC $ \tv -> do+ liftIO . atomically $ modifyTVar tv s+ return ((), tv) -- | Unwrap a concurrent state monad computation as a function. runStateC :: MonadIO m
src/Control/Monad/State/Concurrent/Strict.hs view
@@ -19,6 +19,9 @@ -- *** The StateC monad transformer StateC, + -- *** Specializations of MonadState operations+ modify,+ -- *** Concurrent state operations runStateC, evalStateC, execStateC, @@ -30,7 +33,7 @@ import Control.Arrow (first) import Control.Concurrent.STM import Control.Monad-import Control.Monad.State+import Control.Monad.State hiding (modify) -- --------------------------------------------------------------------------- -- | A concurrent state transformer monad parameterized by:@@ -89,6 +92,18 @@ liftIO i = StateC $ \s -> do a <- liftIO i return (a, s)++-- | Monadic state transformer. Maps an old state to a new state inside+-- a state monad. The old state is thrown away.+--+-- This is provided because "Control.Monad.State"'s modify function is+-- defined in terms of 'get' and 'put', which results in two STM actions+-- for every modify. Instead, 'modify' can be specialized as a call to+-- 'modifyTVar''.+modify :: MonadIO m => (s -> s) -> StateC s m ()+modify s = StateC $ \tv -> do+ liftIO . atomically $ modifyTVar' tv s+ return ((), tv) -- | Unwrap a concurrent state monad computation as a function. runStateC :: MonadIO m