module Control.Monad.Ology.Specific.ReaderStateT where

import Control.Monad.Ology.Data
import Control.Monad.Ology.General
import Control.Monad.Ology.Specific.StateT
import Import

type ReaderStateT f m = StateT (WRaised f m) m

evalReaderStateT :: Monad m => ReaderStateT f m a -> (f --> m) -> m a
evalReaderStateT :: forall (m :: Type -> Type) (f :: Type -> Type) a.
Monad m =>
ReaderStateT f m a -> (f --> m) -> m a
evalReaderStateT ReaderStateT f m a
rsa f --> m
fm = forall (m :: Type -> Type) s a. Monad m => StateT s m a -> s -> m a
evalStateT ReaderStateT f m a
rsa (forall k (p :: k -> Type) (q :: k -> Type).
(p --> q) -> WRaised p q
MkWRaised f --> m
fm)

readerStateLift :: (Monad f, Monad m) => f --> ReaderStateT f m
readerStateLift :: forall (f :: Type -> Type) (m :: Type -> Type).
(Monad f, Monad m) =>
f --> ReaderStateT f m
readerStateLift f a
fa = do
    MkWRaised f --> m
fm <- forall (m :: Type -> Type) s. Monad m => StateT s m s
get
    a
a <- forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ f --> m
fm f a
fa
    forall (m :: Type -> Type) s. Monad m => s -> StateT s m ()
put forall a b. (a -> b) -> a -> b
$ forall k (p :: k -> Type) (q :: k -> Type).
(p --> q) -> WRaised p q
MkWRaised forall a b. (a -> b) -> a -> b
$ \f a
c -> f --> m
fm forall a b. (a -> b) -> a -> b
$ f a
fa forall (m :: Type -> Type) a b. Monad m => m a -> m b -> m b
>> f a
c
    forall (m :: Type -> Type) a. Monad m => a -> m a
return a
a

readerStateUpdate :: Monad m => (f --> f) -> ReaderStateT f m ()
readerStateUpdate :: forall (m :: Type -> Type) (f :: Type -> Type).
Monad m =>
(f --> f) -> ReaderStateT f m ()
readerStateUpdate f --> f
ff = forall (m :: Type -> Type) s. Monad m => (s -> s) -> StateT s m ()
modify (\WRaised f m
fm -> WRaised f m
fm forall {k} (cat :: k -> k -> Type) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall k (p :: k -> Type) (q :: k -> Type).
(p --> q) -> WRaised p q
MkWRaised f --> f
ff)

readerStateParamRef ::
       forall f m. Monad m
    => Param f --> Ref (ReaderStateT f m)
readerStateParamRef :: forall (f :: Type -> Type) (m :: Type -> Type).
Monad m =>
Param f --> Ref (ReaderStateT f m)
readerStateParamRef (Param f a
param :: _ a) = let
    refGet :: ReaderStateT f m a
    refGet :: ReaderStateT f m a
refGet = do
        MkWRaised f --> m
ff <- forall (m :: Type -> Type) s. Monad m => StateT s m s
get
        forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ f --> m
ff forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) a. Param m a -> m a
paramAsk Param f a
param
    refPut :: a -> ReaderStateT f m ()
    refPut :: a -> ReaderStateT f m ()
refPut a
a = forall (m :: Type -> Type) (f :: Type -> Type).
Monad m =>
(f --> f) -> ReaderStateT f m ()
readerStateUpdate forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) a. Param m a -> a -> m --> m
paramWith Param f a
param a
a
    in MkRef {ReaderStateT f m a
a -> ReaderStateT f m ()
refPut :: a -> ReaderStateT f m ()
refGet :: ReaderStateT f m a
refPut :: a -> ReaderStateT f m ()
refGet :: ReaderStateT f m a
..}