{-# LANGUAGE Rank2Types #-}
module Control.Monad.Trans.MSF.State
( module Control.Monad.Trans.State.Strict
, stateS
, runStateS
, runStateS_
, runStateS__
) where
import Control.Applicative
import Control.Monad.Trans.State.Strict
hiding (liftCallCC, liftCatch, liftListen, liftPass)
import Data.Tuple (swap)
import Data.MonadicStreamFunction.Core
import Data.MonadicStreamFunction.InternalCore
stateS :: (Functor m, Monad m) => MSF m (s, a) (s, b) -> MSF (StateT s m) a b
stateS :: MSF m (s, a) (s, b) -> MSF (StateT s m) a b
stateS = (forall c. ((s, a) -> m ((s, b), c)) -> a -> StateT s m (b, c))
-> MSF m (s, a) (s, b) -> MSF (StateT s m) a b
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 c. ((s, a) -> m ((s, b), c)) -> a -> StateT s m (b, c))
-> MSF m (s, a) (s, b) -> MSF (StateT s m) a b)
-> (forall c. ((s, a) -> m ((s, b), c)) -> a -> StateT s m (b, c))
-> MSF m (s, a) (s, b)
-> MSF (StateT s m) a b
forall a b. (a -> b) -> a -> b
$ \(s, a) -> m ((s, b), c)
f a
a -> (s -> m ((b, c), s)) -> StateT s m (b, c)
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT ((s -> m ((b, c), s)) -> StateT s m (b, c))
-> (s -> m ((b, c), s)) -> StateT s m (b, c)
forall a b. (a -> b) -> a -> b
$ \s
s -> (\((s
s', b
b), c
c) -> ((b
b, c
c), s
s'))
(((s, b), c) -> ((b, c), s)) -> m ((s, b), c) -> m ((b, c), 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 :: MSF (StateT s m) a b -> MSF m (s, a) (s, b)
runStateS = (forall c. (a -> StateT s m (b, c)) -> (s, a) -> m ((s, b), c))
-> MSF (StateT s m) a b -> MSF m (s, a) (s, b)
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 c. (a -> StateT s m (b, c)) -> (s, a) -> m ((s, b), c))
-> MSF (StateT s m) a b -> MSF m (s, a) (s, b))
-> (forall c. (a -> StateT s m (b, c)) -> (s, a) -> m ((s, b), c))
-> MSF (StateT s m) a b
-> MSF m (s, a) (s, b)
forall a b. (a -> b) -> a -> b
$ \a -> StateT s m (b, c)
f (s, a) -> (\((b
b, c
c), s
s') -> ((s
s', b
b), c
c))
(((b, c), s) -> ((s, b), c)) -> m ((b, c), s) -> m ((s, b), c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT s m (b, c) -> s -> m ((b, c), s)
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_ :: MSF (StateT s m) a b -> s -> MSF m a (s, b)
runStateS_ MSF (StateT s m) a b
msf s
s = s -> MSF m (a, s) ((s, b), s) -> MSF m a (s, b)
forall (m :: * -> *) c a b.
Monad m =>
c -> MSF m (a, c) (b, c) -> MSF m a b
feedback s
s
(MSF m (a, s) ((s, b), s) -> MSF m a (s, b))
-> MSF m (a, s) ((s, b), s) -> MSF m a (s, b)
forall a b. (a -> b) -> a -> b
$ ((a, s) -> (s, a)) -> MSF m (a, s) (s, a)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (a, s) -> (s, a)
forall a b. (a, b) -> (b, a)
swap MSF m (a, s) (s, a)
-> MSF m (s, a) ((s, b), s) -> MSF m (a, s) ((s, b), s)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> MSF (StateT s m) a b -> MSF m (s, a) (s, b)
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 MSF m (s, a) (s, b)
-> MSF m (s, b) ((s, b), s) -> MSF m (s, a) ((s, b), s)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ((s, b) -> ((s, b), s)) -> MSF m (s, b) ((s, b), s)
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__ :: MSF (StateT s m) a b -> s -> MSF m a b
runStateS__ MSF (StateT s m) a b
msf s
s = MSF (StateT s m) a b -> s -> MSF m a (s, b)
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 MSF m a (s, b) -> MSF m (s, b) b -> MSF m a b
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ((s, b) -> b) -> MSF m (s, b) b
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (s, b) -> b
forall a b. (a, b) -> b
snd