Module

Control.Monad.RWS

This module defines the RWS monad.

#RWS

type RWS r w s = RWST r w s Identity

The RWS monad is a synonym for the RWST monad transformer, applied to the Identity monad.

#rws

rws :: forall r w s a. (r -> s -> RWSResult s a w) -> RWS r w s a

Create an action in the RWS monad from a function which uses the global context and state explicitly.

#runRWS

runRWS :: forall r w s a. RWS r w s a -> r -> s -> RWSResult s a w

Run a computation in the RWS monad.

#evalRWS

evalRWS :: forall r w s a. RWS r w s a -> r -> s -> Tuple a w

Run a computation in the RWS monad, discarding the final state

#execRWS

execRWS :: forall r w s a. RWS r w s a -> r -> s -> Tuple s w

Run a computation in the RWS monad, discarding the result

#mapRWS

mapRWS :: forall r w1 w2 s a1 a2. (RWSResult s a1 w1 -> RWSResult s a2 w2) -> RWS r w1 s a1 -> RWS r w2 s a2

Change the types of the result and accumulator in a RWS action

#withRWS

withRWS :: forall r1 r2 w s a. (r2 -> s -> Tuple r1 s) -> RWS r1 w s a -> RWS r2 w s a

Change the type of the context in a RWS action

Re-exports from Control.Monad.RWS.Trans

#RWST

newtype RWST :: Type -> Type -> Type -> (Type -> Type) -> Type -> Typenewtype RWST r w s m a

The reader-writer-state monad transformer, which combines the operations of ReaderT, WriterT and StateT into a single monad transformer.

Constructors

Instances

#RWSResult

data RWSResult state result writer

Constructors

#MonadTrans

class MonadTrans :: ((Type -> Type) -> Type -> Type) -> Constraintclass MonadTrans t  where

The MonadTrans type class represents monad transformers.

A monad transformer is a type constructor of kind (* -> *) -> * -> *, which takes a Monad as its first argument, and returns another Monad.

This allows us to add additional effects to an existing monad. By iterating this process, we create monad transformer stacks, which contain all of the effects required for a particular computation.

The laws state that lift is a Monad morphism.

Laws:

  • lift (pure a) = pure a
  • lift (do { x <- m ; y }) = do { x <- lift m ; lift y }

Members

#withRWST

withRWST :: forall r1 r2 w s m a. (r2 -> s -> Tuple r1 s) -> RWST r1 w s m a -> RWST r2 w s m a

Change the context type in a RWST monad action.

#runRWST

runRWST :: forall r w s m a. RWST r w s m a -> r -> s -> m (RWSResult s a w)

Run a computation in the RWST monad.

#mapRWST

mapRWST :: forall r w1 w2 s m1 m2 a1 a2. (m1 (RWSResult s a1 w1) -> m2 (RWSResult s a2 w2)) -> RWST r w1 s m1 a1 -> RWST r w2 s m2 a2

Change the result and accumulator types in a RWST monad action.

#execRWST

execRWST :: forall r w s m a. Monad m => RWST r w s m a -> r -> s -> m (Tuple s w)

Run a computation in the RWST monad, discarding the result.

#evalRWST

evalRWST :: forall r w s m a. Monad m => RWST r w s m a -> r -> s -> m (Tuple a w)

Run a computation in the RWST monad, discarding the final state.

Re-exports from Control.Monad.Reader.Class

#ask

ask :: forall r m. MonadAsk r m => m r

#local

local :: forall r m a. MonadReader r m => (r -> r) -> m a -> m a

#asks

asks :: forall r m a. MonadAsk r m => (r -> a) -> m a

Projects a value from the global context in a MonadAsk.

Re-exports from Control.Monad.State.Class

#state

state :: forall s m a. MonadState s m => (s -> (Tuple a s)) -> m a

#put

put :: forall m s. MonadState s m => s -> m Unit

Set the state.

#modify_

modify_ :: forall s m. MonadState s m => (s -> s) -> m Unit

#modify

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

Modify the state by applying a function to the current state. The returned value is the new state value.

#gets

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

Get a value which depends on the current state.

#get

get :: forall m s. MonadState s m => m s

Get the current state.

Re-exports from Control.Monad.Writer.Class

#listen

listen :: forall w m a. MonadWriter w m => m a -> m (Tuple a w)

#pass

pass :: forall w m a. MonadWriter w m => m (Tuple a (w -> w)) -> m a

#tell

tell :: forall w m. MonadTell w m => w -> m Unit

#listens

listens :: forall w m a b. MonadWriter w m => (w -> b) -> m a -> m (Tuple a b)

Projects a value from modifications made to the accumulator during an action.

#censor

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

Modify the final accumulator value by applying a function.

Modules