{-# LANGUAGE CPP #-}
module Control.Monad.Trans.MSF.State
( module Control.Monad.Trans.State.Strict
, stateS
, runStateS
, runStateS_
, runStateS__
)
where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
#endif
import Control.Arrow (arr, (>>>))
import Control.Monad.Trans.State.Strict hiding (liftCallCC, liftCatch,
liftListen, liftPass)
import Data.Tuple (swap)
import Data.MonadicStreamFunction.Core (MSF, morphGS, feedback)
stateS :: (Functor m, Monad m) => MSF m (s, a) (s, b) -> MSF (StateT s m) a b
stateS :: forall (m :: * -> *) s a b.
(Functor m, Monad m) =>
MSF m (s, a) (s, b) -> MSF (StateT s m) a b
stateS = forall (m2 :: * -> *) a1 (m1 :: * -> *) b1 a2 b2.
Monad m2 =>
(forall c. (a1 -> m1 (b1, c)) -> a2 -> m2 (b2, c))
-> MSF m1 a1 b1 -> MSF m2 a2 b2
morphGS forall a b. (a -> b) -> a -> b
$ \(s, a) -> m ((s, b), c)
f a
a -> forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT forall a b. (a -> b) -> a -> b
$ \s
s -> (\((s
s', b
b), c
c) -> ((b
b, c
c), s
s'))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (s, a) -> m ((s, b), c)
f (s
s, a
a)
runStateS :: (Functor m, Monad m) => MSF (StateT s m) a b -> MSF m (s, a) (s, b)
runStateS :: forall (m :: * -> *) s a b.
(Functor m, Monad m) =>
MSF (StateT s m) a b -> MSF m (s, a) (s, b)
runStateS = forall (m2 :: * -> *) a1 (m1 :: * -> *) b1 a2 b2.
Monad m2 =>
(forall c. (a1 -> m1 (b1, c)) -> a2 -> m2 (b2, c))
-> MSF m1 a1 b1 -> MSF m2 a2 b2
morphGS forall a b. (a -> b) -> a -> b
$ \a -> StateT s m (b, c)
f (s
s, a
a) -> (\((b
b, c
c), s
s') -> ((s
s', b
b), c
c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (a -> StateT s m (b, c)
f a
a) s
s
runStateS_ :: (Functor m, Monad m)
=> MSF (StateT s m) a b
-> s
-> MSF m a (s, b)
runStateS_ :: forall (m :: * -> *) s a b.
(Functor m, Monad m) =>
MSF (StateT s m) a b -> s -> MSF m a (s, b)
runStateS_ MSF (StateT s m) a b
msf s
s =
forall (m :: * -> *) c a b.
Monad m =>
c -> MSF m (a, c) (b, c) -> MSF m a b
feedback s
s forall a b. (a -> b) -> a -> b
$
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall a b. (a, b) -> (b, a)
swap forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (m :: * -> *) s a b.
(Functor m, Monad m) =>
MSF (StateT s m) a b -> MSF m (s, a) (s, b)
runStateS MSF (StateT s m) a b
msf forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\(s
s', b
b) -> ((s
s', b
b), s
s'))
runStateS__ :: (Functor m, Monad m) => MSF (StateT s m) a b -> s -> MSF m a b
runStateS__ :: forall (m :: * -> *) s a b.
(Functor m, Monad m) =>
MSF (StateT s m) a b -> s -> MSF m a b
runStateS__ MSF (StateT s m) a b
msf s
s = forall (m :: * -> *) s a b.
(Functor m, Monad m) =>
MSF (StateT s m) a b -> s -> MSF m a (s, b)
runStateS_ MSF (StateT s m) a b
msf s
s forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall a b. (a, b) -> b
snd