module Control.Effect.RWS.Lazy
(
evalRWS'
, execRWS'
, runRWS'
, evalRWS
, execRWS
, runRWS
) where
import Control.Monad.Trans.RWS.Lazy (RWST, runRWST)
import Control.Effect.Machinery (EachVia, G, runVia)
import Control.Effect.Reader (Reader, Reader')
import Control.Effect.RWS (RWS, RWS')
import Control.Effect.State (State, State')
import Control.Effect.Writer (Writer, Writer')
evalRWS'
:: forall tag r w s m a. Functor m
=> r
-> s
-> ('[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s] `EachVia` RWST r w s) m a
-> m (w, a)
evalRWS' :: r
-> s
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, a)
evalRWS' r :: r
r s :: s
s = ((a, s, w) -> (w, a)) -> m (a, s, w) -> m (w, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s, w) -> (w, a)
forall b b a. (b, b, a) -> (a, b)
reorder (m (a, s, w) -> m (w, a))
-> (EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (a, s, w))
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\m :: RWST r w s m a
m -> RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s) (RWST r w s m a -> m (a, s, w))
-> (EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> RWST r w s m a)
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (a, s, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> RWST r w s m a
forall (effs :: [(* -> *) -> Constraint]) (t :: Transformer)
(m :: * -> *) a.
EachVia effs t m a -> t m a
runVia
where
reorder :: (b, b, a) -> (a, b)
reorder (a :: b
a, _, w :: a
w) = (a
w, b
a)
{-# INLINE evalRWS' #-}
evalRWS :: Functor m => r -> s -> ('[RWS r w s, Reader r, Writer w, State s] `EachVia` RWST r w s) m a -> m (w, a)
evalRWS :: r
-> s
-> EachVia
'[RWS r w s, Reader r, Writer w, State s] (RWST r w s) m a
-> m (w, a)
evalRWS = forall k (tag :: k) r w s (m :: * -> *) a.
Functor m =>
r
-> s
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, a)
forall r w s (m :: * -> *) a.
Functor m =>
r
-> s
-> EachVia
'[RWS' G r w s, Reader' G r, Writer' G w, State' G s]
(RWST r w s)
m
a
-> m (w, a)
evalRWS' @G
{-# INLINE evalRWS #-}
execRWS'
:: forall tag r w s m a. Functor m
=> r
-> s
-> ('[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s] `EachVia` RWST r w s) m a
-> m (w, s)
execRWS' :: r
-> s
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, s)
execRWS' r :: r
r s :: s
s = ((a, s, w) -> (w, s)) -> m (a, s, w) -> m (w, s)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s, w) -> (w, s)
forall a b a. (a, b, a) -> (a, b)
reorder (m (a, s, w) -> m (w, s))
-> (EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (a, s, w))
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\m :: RWST r w s m a
m -> RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s) (RWST r w s m a -> m (a, s, w))
-> (EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> RWST r w s m a)
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (a, s, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> RWST r w s m a
forall (effs :: [(* -> *) -> Constraint]) (t :: Transformer)
(m :: * -> *) a.
EachVia effs t m a -> t m a
runVia
where
reorder :: (a, b, a) -> (a, b)
reorder (_, s' :: b
s', w :: a
w) = (a
w, b
s')
{-# INLINE execRWS' #-}
execRWS :: Functor m => r -> s -> ('[RWS r w s, Reader r, Writer w, State s] `EachVia` RWST r w s) m a -> m (w, s)
execRWS :: r
-> s
-> EachVia
'[RWS r w s, Reader r, Writer w, State s] (RWST r w s) m a
-> m (w, s)
execRWS = forall k (tag :: k) r w s (m :: * -> *) a.
Functor m =>
r
-> s
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, s)
forall r w s (m :: * -> *) a.
Functor m =>
r
-> s
-> EachVia
'[RWS' G r w s, Reader' G r, Writer' G w, State' G s]
(RWST r w s)
m
a
-> m (w, s)
execRWS' @G
{-# INLINE execRWS #-}
runRWS'
:: forall tag r w s m a. Functor m
=> r
-> s
-> ('[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s] `EachVia` RWST r w s) m a
-> m (w, s, a)
runRWS' :: r
-> s
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, s, a)
runRWS' r :: r
r s :: s
s = ((a, s, w) -> (w, s, a)) -> m (a, s, w) -> m (w, s, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s, w) -> (w, s, a)
forall c b a. (c, b, a) -> (a, b, c)
reorder (m (a, s, w) -> m (w, s, a))
-> (EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (a, s, w))
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, s, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\m :: RWST r w s m a
m -> RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s) (RWST r w s m a -> m (a, s, w))
-> (EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> RWST r w s m a)
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (a, s, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> RWST r w s m a
forall (effs :: [(* -> *) -> Constraint]) (t :: Transformer)
(m :: * -> *) a.
EachVia effs t m a -> t m a
runVia
where
reorder :: (c, b, a) -> (a, b, c)
reorder (a :: c
a, s' :: b
s', w :: a
w) = (a
w, b
s', c
a)
{-# INLINE runRWS' #-}
runRWS :: Functor m => r -> s -> ('[RWS r w s, Reader r, Writer w, State s] `EachVia` RWST r w s) m a -> m (w, s, a)
runRWS :: r
-> s
-> EachVia
'[RWS r w s, Reader r, Writer w, State s] (RWST r w s) m a
-> m (w, s, a)
runRWS = forall k (tag :: k) r w s (m :: * -> *) a.
Functor m =>
r
-> s
-> EachVia
'[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s]
(RWST r w s)
m
a
-> m (w, s, a)
forall r w s (m :: * -> *) a.
Functor m =>
r
-> s
-> EachVia
'[RWS' G r w s, Reader' G r, Writer' G w, State' G s]
(RWST r w s)
m
a
-> m (w, s, a)
runRWS' @G
{-# INLINE runRWS #-}