Module

Control.Monad.RWS

Package
purescript-transformers
Repository
purescript/purescript-transformers

This module defines the RWS monad.

#RWS Source

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 Source

rws :: forall a s w r. (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 Source

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

Run a computation in the RWS monad.

#evalRWS Source

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

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

#execRWS Source

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

Run a computation in the RWS monad, discarding the result

#mapRWS Source

mapRWS :: forall a2 a1 s w2 w1 r. (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 Source

withRWS :: forall a s w r2 r1. (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 Source

newtype 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 Source

data RWSResult state result writer

Constructors

#MonadTrans Source

class 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 Source

withRWST :: forall a m s w r2 r1. (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 Source

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

Run a computation in the RWST monad.

#mapRWST Source

mapRWST :: forall a2 a1 m2 m1 s w2 w1 r. (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 Source

execRWST :: forall a m s w r. 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 Source

evalRWST :: forall a m s w r. 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 Source

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

#local Source

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

#asks Source

asks :: forall a m r. 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 Source

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

#put Source

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

Set the state.

#modify Source

modify :: forall m s. 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 Source

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

Get a value which depends on the current state.

#get Source

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

Get the current state.

Re-exports from Control.Monad.Writer.Class

#listen Source

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

#pass Source

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

#tell Source

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

#listens Source

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

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

#censor Source

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

Modify the final accumulator value by applying a function.