packages feed

mstate 0.1 → 0.1.1

raw patch · 2 files changed

+36/−2 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.Concurrent.MState: instance (MonadCont m) => MonadCont (MState t m)
+ Control.Concurrent.MState: instance (MonadError e m) => MonadError e (MState t m)
+ Control.Concurrent.MState: instance (MonadFix m) => MonadFix (MState t m)
+ Control.Concurrent.MState: instance (MonadIO m, MonadWriter w m) => MonadWriter w (MState t m)
+ Control.Concurrent.MState: instance (MonadReader r m) => MonadReader r (MState t m)
+ Control.Concurrent.MState: instance Forkable (ReaderT s IO)

Files

mstate.cabal view
@@ -8,7 +8,7 @@ Author:         Nils Schweinsberg Maintainer:     <mail@n-sch.de> -Version:        0.1+Version:        0.1.1 Category:       Concurrent, Monads License:        BSD3 License-File:   LICENSE
src/Control/Concurrent/MState.hs view
@@ -34,7 +34,10 @@  import Control.Monad import Control.Monad.State.Class-import Control.Monad.Trans+import Control.Monad.Cont+import Control.Monad.Error+import Control.Monad.Reader+import Control.Monad.Writer  import Control.Concurrent import Data.IORef@@ -53,10 +56,14 @@ class (MonadIO m) => Forkable m where     fork :: m () -> m ThreadId + instance Forkable IO where     fork = forkIO +instance Forkable (ReaderT s IO) where+    fork newT = ask >>= liftIO . forkIO . runReaderT newT + catchMVar :: IO a -> (E.BlockedIndefinitelyOnMVar -> IO a) -> IO a catchMVar = E.catch @@ -175,11 +182,38 @@     get     = MState $ \(r,_) -> liftIO $ readIORef r     put val = MState $ \(r,_) -> liftIO $ writeIORef r val +instance (MonadFix m) => MonadFix (MState t m) where+    mfix f = MState $ \s -> mfix $ \a -> runMState' (f a) s+++--------------------------------------------------------------------------------+-- mtl instances+--------------------------------------------------------------------------------+ instance MonadTrans (MState t) where     lift m = MState $ \_ -> m  instance (MonadIO m) => MonadIO (MState t m) where     liftIO = lift . liftIO++instance (MonadCont m) => MonadCont (MState t m) where+    callCC f = MState $ \s ->+        callCC $ \c ->+            runMState' (f (\a -> MState $ \_ -> c a)) s++instance (MonadError e m) => MonadError e (MState t m) where+    throwError       = lift . throwError+    m `catchError` h = MState $ \s ->+        runMState' m s `catchError` \e -> runMState' (h e) s++instance (MonadReader r m) => MonadReader r (MState t m) where+    ask       = lift ask+    local f m = MState $ \s -> local f (runMState' m s)++instance (MonadIO m, MonadWriter w m) => MonadWriter w (MState t m) where+    tell     = lift . tell+    listen m = MState $ listen . runMState' m+    pass   m = MState $ pass   . runMState' m   {- $example