Community
Modules 24

Control.Monad.RWS.Class

experimental

Declaration of the MonadRWS class.

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 (Monoid w, MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s m

module Control.Monad.Reader.Class mtl-2.3.2 · 2 declarations

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.

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.

module Control.Monad.State.Class mtl-2.3.2 · 4 declarations

gets :: MonadState s m => (s -> a) -> m a

Gets specific component of the state, using a projection function supplied.

modify :: MonadState s m => (s -> s) -> m ()

Monadic state transformer.

Maps an old state to a new state inside a state monad. The old state is thrown away.

     Main> :t modify ((+1) :: Int -> Int)
     modify (...) :: (MonadState Int a) => a ()

This says that modify (+1) acts over any Monad that is a member of the MonadState class, with an Int state.

modify' :: MonadState s m => (s -> s) -> m ()

A variant of modify in which the computation is strict in the new state.

class Monad m => MonadState s m

Minimal definition is either both of get and put or just state

get :: m s

Return the state from the internals of the monad.

put :: s -> m ()

Replace the state inside the monad.

state :: (s -> (a, s)) -> m a

Embed a simple state action into the monad.

module Control.Monad.Writer.Class mtl-2.3.2 · 3 declarations

censor :: MonadWriter w m => (w -> w) -> m a -> m a

censor f m is an action that executes the action m and applies the function f to its output, leaving the return value unchanged.

  • censor f m = pass (liftM (\x -> (x,f)) m)

listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b)

listens f m is an action that executes the action m and adds the result of applying f to the output to the value of the computation.

  • listens f m = liftM (id *** f) (listen m)

class (Monoid w, Monad m) => MonadWriter w m

writer :: (a, w) -> m a

writer (a,w) embeds a simple writer action.

tell :: w -> m ()

tell w is an action that produces the output w.

listen :: m a -> m (a, w)

listen m is an action that executes the action m and adds its output to the value of the computation.

pass :: m (a, w -> w) -> m a

pass m is an action that executes the action m, which returns a value and a function, and returns the value, applying the function to the output.

Instances

7
  • instance (Monoid w, Monad m) => MonadRWS r w s (CPS.RWST r w s m)
  • instance (Monoid w, Monad m) => MonadRWS r w s (Lazy.RWST r w s m)
  • instance (Monoid w, Monad m) => MonadRWS r w s (Strict.RWST r w s m)
  • instance MonadRWS r w s m => MonadRWS r w s (ExceptT e m)
  • instance MonadRWS r w s m => MonadRWS r w s (IdentityT m)
  • instance MonadRWS r w s m => MonadRWS r w s (MaybeT m)
  • instance (MonadRWS r w s m, MonadRWS r w s n) => MonadRWS r w s (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
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.