{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -Wall -fwarn-tabs #-}
module Control.Monad.State.UnificationExtras
(
liftReader
, liftReaderT
, modify'
, localState
) where
import Control.Monad (liftM)
import Control.Monad.Reader (Reader(), ReaderT(..))
import Control.Monad.State.Lazy (MonadState(..), State(), StateT(..))
liftReaderT :: (Monad m) => ReaderT e m a -> StateT e m a
{-# INLINE liftReaderT #-}
liftReaderT :: ReaderT e m a -> StateT e m a
liftReaderT ReaderT e m a
r = (e -> m (a, e)) -> StateT e m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT ((e -> m (a, e)) -> StateT e m a)
-> (e -> m (a, e)) -> StateT e m a
forall a b. (a -> b) -> a -> b
$ \e
e -> (a -> (a, e)) -> m a -> m (a, e)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\a
a -> (a
a,e
e)) (ReaderT e m a -> e -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT e m a
r e
e)
liftReader :: Reader e a -> State e a
{-# INLINE liftReader #-}
liftReader :: Reader e a -> State e a
liftReader = Reader e a -> State e a
forall (m :: * -> *) e a. Monad m => ReaderT e m a -> StateT e m a
liftReaderT
modify' :: (MonadState s m) => (s -> s) -> m ()
{-# INLINE modify' #-}
modify' :: (s -> s) -> m ()
modify' s -> s
f = do
s
s <- m s
forall s (m :: * -> *). MonadState s m => m s
get
s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (s -> m ()) -> s -> m ()
forall a b. (a -> b) -> a -> b
$! s -> s
f s
s
localState :: (MonadState s m) => m a -> m a
{-# INLINE localState #-}
localState :: m a -> m a
localState m a
m = do
s
s <- m s
forall s (m :: * -> *). MonadState s m => m s
get
a
x <- m a
m
s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put s
s
a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x