mstate 0.2.7 → 0.2.8
raw patch · 2 files changed
+17/−7 lines, 2 filesdep +faildep ~base
Dependencies added: fail
Dependency ranges changed: base
Files
- mstate.cabal +7/−2
- src/Control/Concurrent/MState.hs +10/−5
mstate.cabal view
@@ -8,13 +8,17 @@ Author: Nils Schweinsberg Maintainer: <mail@nils.cc> -Version: 0.2.7+Version: 0.2.8 Category: Concurrency, Monads License: BSD3 License-File: LICENSE Cabal-Version: >= 1.6 Build-Type: Simple +source-repository head+ type: git+ location: https://github.com/nilscc/mstate+ Library GHC-Options: -Wall Hs-Source-Dirs: src@@ -22,7 +26,8 @@ base == 4.*, mtl, stm,- monad-peel >= 0.1.1+ monad-peel >= 0.1.1,+ fail Exposed-Modules: Control.Concurrent.MState
src/Control/Concurrent/MState.hs view
@@ -42,7 +42,8 @@ import Control.Applicative import Control.Monad.State.Class import Control.Monad.Cont-import Control.Monad.Error+import Control.Monad.Except+import qualified Control.Monad.Fail as Fail import Control.Monad.Reader import Control.Monad.Writer @@ -72,8 +73,10 @@ -> t -- ^ Initial state value -> m (a,t) runMState m t = do- (a, Just t') <- runAndWaitMaybe True m t- return (a, t')+ (a, t') <- runAndWaitMaybe True m t+ case t' of+ Just t'' -> return (a, t'')+ _ -> undefined -- impossible runAndWaitMaybe :: MonadPeelIO m => Bool@@ -130,7 +133,7 @@ liftIO . atomically $ writeTVar r v' return b -mapMState_ :: (MonadIO m, MonadIO n)+mapMState_ :: (MonadIO n) => (m a -> n b) -> MState t m a -> MState t n b@@ -221,12 +224,14 @@ -- Monad instances -------------------------------------------------------------------------------- +instance (Fail.MonadFail m) => Fail.MonadFail (MState t m) where+ fail str = MState $ \_ -> Fail.fail str+ instance (Monad m) => Monad (MState t m) where return a = MState $ \_ -> return a m >>= k = MState $ \t -> do a <- runMState' m t runMState' (k a) t- fail str = MState $ \_ -> fail str instance (Functor f) => Functor (MState t f) where fmap f m = MState $ \t -> fmap f (runMState' m t)