Community
Modules 24

Control.Monad.Reader.Class

experimental
Computation type:
Computations which read values from a shared environment.
Binding strategy:
Monad values are functions from the environment to a value.

The bound function is applied to the bound value, and both have access to the shared environment.

Useful for:
Maintaining variable bindings, or other shared environment.
Zero and plus:
None.
Example type:
Reader [(String,Value)] a

The Reader monad (also called the Environment monad). Represents a computation, which can read values from a shared environment, pass values from function to function, and execute sub-computations in a modified environment. Using Reader monad for such computations is often clearer and easier than using the State monad.

Inspired by the paper Functional Programming with Overloading and Higher-Order Polymorphism, Mark P Jones (http://web.cecs.pdx.edu/~mpj/) Advanced School of Functional Programming, 1995.

class Monad m => MonadReader r m

See examples in Control.Monad.Reader. Note, the partially applied function type (->) r is a simple reader monad. See the instance declaration below.

ask :: m r

Retrieves the monad environment.

local :: (r -> r) -> m a -> m a

Executes a computation in a modified environment.

Reader to run in the modified environment.

(r -> r)

The function to modify the environment.

reader :: (r -> a) -> m a

Retrieves a function of the current environment.

(r -> a)

The selector function to apply to the environment.

asks :: MonadReader r m => (r -> a) -> m a

Retrieves a function of the current environment.

(r -> a)

The selector function to apply to the environment.

Instances

17
  • instance MonadReader r ((->) r)
  • instance Monad m => MonadReader r (ReaderT r m)
  • instance (Monad m, Monoid w) => MonadReader r (CPSRWS.RWST r w s m)
  • instance (Monad m, Monoid w) => MonadReader r (LazyRWS.RWST r w s m)
  • instance (Monad m, Monoid w) => MonadReader r (StrictRWS.RWST r w s m)
  • instance MonadReader r' m => MonadReader r' (ContT r m)
  • instance MonadReader r m => MonadReader r (ExceptT e m)
  • instance MonadReader r m => MonadReader r (IdentityT m)
  • instance MonadReader r m => MonadReader r (MaybeT m)
  • instance MonadReader r m => MonadReader r (Lazy.StateT s m)
  • instance MonadReader r m => MonadReader r (Strict.StateT s m)
  • instance (Monoid w, MonadReader r m) => MonadReader r (CPS.WriterT w m)
  • instance (Monoid w, MonadReader r m) => MonadReader r (Lazy.WriterT w m)
  • instance (Monoid w, MonadReader r m) => MonadReader r (Strict.WriterT w m)
  • instance (Monoid w, MonadReader r m) => MonadReader r (AccumT w m)
  • instance (MonadReader r' m) => MonadReader r' (SelectT r m)
  • instance (MonadReader r m, MonadReader r n) => MonadReader r (Product m n)
Maintainer
libraries@haskell.org
Portability
non-portable (multi-param classes, functional dependencies)
Copyright
(c) Andy Gill 2001, (c) Oregon Graduate Institute of Science and Technology 2001, (c) Jeff Newbern 2003-2007, (c) Andriy Palamarchuk 2007
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 6 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 032b29dc8ecd03eaae7b1a84a40ef8560125381762749b2f47333bc9a4f4bb8e

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.