HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulerelude-1.2.2.2Haskell2010

Relude.Monad.Trans

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

Monad transformers utilities.

Contents
  1. Convenient functions to work with Reader monad
  2. Convenient functions to work with State monad
  3. Lifted to Transformers
Synopsis
  • Packagerelude-1.2.2.2
  • Exports11
  • LanguageHaskell2010
  • LicenceMIT
  • SourceTrans.hs

Convenient functions to work with Reader monad

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

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.

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