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

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

data RWSResult state result writer

Constructors

#MonadTrans Source

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 Source

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 Source

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 Source

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 Source

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 Source

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 Source

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

#local Source

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

#asks Source

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 Source

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

#put Source

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

Set the state.

#modify_ Source

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

#modify Source

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 Source

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

Get a value which depends on the current state.

#get Source

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

Get the current state.

Re-exports from Control.Monad.Writer.Class

#listen Source

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

#pass Source

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

#tell Source

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

#listens Source

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 Source

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

Modify the final accumulator value by applying a function.