{-# OPTIONS_GHC -Wall #-}
{-|
Description: Type synonyms and run functions for pairwise compositions of reader, writer and state transformers.

* RST
* RWT
* WST
-}
module Parser.Transf (RST, RWT, WST, evalRST, evalWST, execRST, execRWT, execWST, runRST, runRWT, runWST) where
  import Control.Monad.RWS.Strict (RWST (..))
  -- | The composition of reader and state transformers.

  type RST env = RWST env ()
  -- | The composition of reader and writer transformers.

  type RWT env res = RWST env res ()
  -- | The composition of writer and state transformers.

  type WST = RWST ()
  -- | Discards the end state.

  evalRST :: Functor f => RST env state f t -> env -> state -> f t
  evalRST :: RST env state f t -> env -> state -> f t
evalRST (RWST env -> state -> f (t, state, ())
f) env
env state
st = (\(t
x, state
_, ()
_) -> t
x) ((t, state, ()) -> t) -> f (t, state, ()) -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> env -> state -> f (t, state, ())
f env
env state
st
  -- | Discards the end state.

  evalWST :: Functor f => WST res state f t -> state -> f (t, res)
  evalWST :: WST res state f t -> state -> f (t, res)
evalWST (RWST () -> state -> f (t, state, res)
f) state
st = (\(t
x, state
_, res
res) -> (t
x, res
res)) ((t, state, res) -> (t, res)) -> f (t, state, res) -> f (t, res)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> () -> state -> f (t, state, res)
f () state
st
  -- | Discards the output.

  execRST :: Functor f => RST env state f t -> env -> state -> f state
  execRST :: RST env state f t -> env -> state -> f state
execRST (RWST env -> state -> f (t, state, ())
f) env
env state
st = (\(t
_, state
st', ()
_) -> state
st') ((t, state, ()) -> state) -> f (t, state, ()) -> f state
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> env -> state -> f (t, state, ())
f env
env state
st
  -- | Discards the output.

  execRWT :: Functor f => RWT env res f t -> env -> f res
  execRWT :: RWT env res f t -> env -> f res
execRWT (RWST env -> () -> f (t, (), res)
f) env
env = (\(t
_, (), res
res) -> res
res) ((t, (), res) -> res) -> f (t, (), res) -> f res
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> env -> () -> f (t, (), res)
f env
env ()
  -- | Discards the output.

  execWST :: Functor f => WST res state f t -> state -> f (state, res)
  execWST :: WST res state f t -> state -> f (state, res)
execWST (RWST () -> state -> f (t, state, res)
f) state
st = (\(t
_, state
st', res
res) -> (state
st', res
res)) ((t, state, res) -> (state, res))
-> f (t, state, res) -> f (state, res)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> () -> state -> f (t, state, res)
f () state
st
  -- | Runs the RS transformer.

  runRST :: Functor f => RST env state f t -> env -> state -> f (t, state)
  runRST :: RST env state f t -> env -> state -> f (t, state)
runRST (RWST env -> state -> f (t, state, ())
f) env
env state
st = (\(t
x, state
st', ()) -> (t
x, state
st')) ((t, state, ()) -> (t, state)) -> f (t, state, ()) -> f (t, state)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> env -> state -> f (t, state, ())
f env
env state
st
  -- | Runs the RW transformer.

  runRWT :: Functor f => RWT env res f t -> env -> f (t, res)
  runRWT :: RWT env res f t -> env -> f (t, res)
runRWT (RWST env -> () -> f (t, (), res)
f) env
env = (\(t
x, (), res
res) -> (t
x, res
res)) ((t, (), res) -> (t, res)) -> f (t, (), res) -> f (t, res)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> env -> () -> f (t, (), res)
f env
env ()
  -- | Runs the WS transformer.

  runWST :: WST res state f t -> state -> f (t, state, res)
  runWST :: WST res state f t -> state -> f (t, state, res)
runWST (RWST () -> state -> f (t, state, res)
f) = () -> state -> f (t, state, res)
f ()