{-# LANGUAGE TemplateHaskell #-}
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, makeUntagged, 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 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
. (\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 (b
a, b
_, a
w) = (a
w, b
a)
{-# 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 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
. (\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 (a
_, b
s', a
w) = (a
w, b
s')
{-# 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 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
. (\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 (c
a, b
s', a
w) = (a
w, b
s', c
a)
{-# INLINE runRWS' #-}
makeUntagged ['evalRWS', 'execRWS', 'runRWS']