HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulerelude-1.2.0.0Haskell2010

Relude.Monad.Trans

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Monad transformers utilities.

  • 11 values
  • Packagerelude-1.2.0.0
  • Exports11
  • LanguageHaskell2010
  • LicenceMIT
  • SourceTrans.hs

Convenient functions to work with Reader monad

3 declarations
valueusingReader :: r -> Reader r a -> a
#

Shorter and more readable alias for flip runReader.

Example1 expression
usingReader 42 $ asks (+5)47
valueusingReaderT :: r -> ReaderT r m a -> m a
#

Shorter and more readable alias for flip runReaderT.

Example1 expression
usingReaderT 42 $ asks (+5)47
valueetaReaderT :: ReaderT r m a -> ReaderT r m a
#

This function helps with optimizing performance when working with the ReaderT transformer. If you have code like below, that is called in a loop

step :: Instruction -> ReaderT Config IO Result
step instruction = case instruction of
    Add -> do stuff ...
    Del -> do stuff ...

you can improve performance of your Haskell applications by using etaReaderT in the following way:

step :: Instruction -> ReaderT Config IO Result
step instruction = etaReaderT $ case instruction of
    Add -> do stuff ...
    Del -> do stuff ...

For a detailed explanation, refer to the following blog post:

Convenient functions to work with State monad

6 declarations
valueevaluatingState :: s -> State s a -> a
#

Alias for flip evalState. It's not shorter but sometimes more readable. Done by analogy with using* functions family.

valueevaluatingStateT :: Functor f => s -> StateT s f a -> f a
#

Alias for flip evalStateT. It's not shorter but sometimes more readable. Done by analogy with using* functions family.

valueexecutingState :: s -> State s a -> s
#

Alias for flip execState. It's not shorter but sometimes more readable. Done by analogy with using* functions family.

valueexecutingStateT :: Functor f => s -> StateT s f a -> f s
#

Alias for flip execStateT. It's not shorter but sometimes more readable. Done by analogy with using* functions family.

valueusingState :: s -> State s a -> (a, s)
#

Shorter and more readable alias for flip runState.

valueusingStateT :: s -> StateT s m a -> m (a, s)
#

Shorter and more readable alias for flip runStateT.

Example1 expression
usingStateT 0 $ put 42 >> pure False(False,42)

Lifted to Transformers

2 declarations