effet-0.3.0.1: An Effect System based on Type Classes

Copyright(c) Michael Szvetits 2020
LicenseBSD3 (see the file LICENSE)
Maintainertypedbyte@qualified.name
Stabilitystable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Control.Effect.RWS

Contents

Description

The effect that combines the reader, writer and state effect, similar to the MonadRWS type class from the mtl library.

Lazy and strict interpretations of the effect are available here: Control.Effect.RWS.Lazy and Control.Effect.RWS.Strict.

Synopsis

Tagged RWS Effect

class (Reader' tag r m, Writer' tag w m, State' tag s m) => RWS' tag r w s m | tag m -> r w s Source #

An effect that adds the following features to a given computation:

  • (R) an immutable environment (the "reader" part)
  • (W) a write-only, accumulated output (the "writer" part)
  • (S) a mutable state (the "state" part)

Since: 0.2.0.0

Instances
(Reader' tag r m, Writer' tag w m, State' tag s m) => RWS' (tag :: k) r w s (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Control (RWS' tag r w s) t m => RWS' (tag :: k) r w s (EachVia ([] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.RWS

Find (RWS' tag r w s) effs t m => RWS' (tag :: k) r w s (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.RWS

(Monad (t m), Reader' tag r (EachVia effs t m), Writer' tag w (EachVia effs t m), State' tag s (EachVia effs t m)) => RWS' (tag :: k) r w s (EachVia (RWS' tag r w s ': effs) t m) Source # 
Instance details

Defined in Control.Effect.RWS

(Monad m, Monoid w) => RWS' (tag :: k) r w s (RWST r w s m) Source # 
Instance details

Defined in Control.Effect.RWS

(Monad m, Monoid w) => RWS' (tag :: k) r w s (RWST r w s m) Source # 
Instance details

Defined in Control.Effect.RWS

(Monad m, Monoid w) => RWS' (tag :: k) r w s (RWST r w s m) Source # 
Instance details

Defined in Control.Effect.RWS.Strict

RWS' new r w s m => RWS' (tag :: k1) r w s (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Untagged RWS Effect

If you don't require disambiguation of multiple RWS effects (i.e., you only have one RWS effect in your monadic context), it is recommended to always use the untagged RWS effect.

type RWS r w s = RWS' G r w s Source #

Interpretations

data Separation m a Source #

The separation interpreter of the RWS effect. This type implements the RWS' type class by splitting the effect into separate Reader', Writer' and State' effects which can then be interpreted individually.

When interpreting the effect, you usually don't interact with this type directly, but instead use one of its corresponding interpretation functions.

Instances
(Reader' tag r m, Writer' tag w m, State' tag s m) => RWS' (tag :: k) r w s (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Reader' tag r m => Reader' (tag :: k) r (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

ask' :: Separation m r Source #

local' :: (r -> r) -> Separation m a -> Separation m a Source #

reader' :: (r -> a) -> Separation m a Source #

State' tag s m => State' (tag :: k) s (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

get' :: Separation m s Source #

put' :: s -> Separation m () Source #

state' :: (s -> (s, a)) -> Separation m a Source #

Writer' tag w m => Writer' (tag :: k) w (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

tell' :: w -> Separation m () Source #

listen' :: Separation m a -> Separation m (w, a) Source #

censor' :: (w -> w) -> Separation m a -> Separation m a Source #

MonadBase b m => MonadBase b (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

liftBase :: b α -> Separation m α #

MonadBaseControl b m => MonadBaseControl b (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Associated Types

type StM (Separation m) a :: Type #

Methods

liftBaseWith :: (RunInBase (Separation m) b -> b a) -> Separation m a #

restoreM :: StM (Separation m) a -> Separation m a #

MonadTrans (Separation :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

lift :: Monad m => m a -> Separation m a #

MonadTransControl (Separation :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Control.Effect.RWS

Associated Types

type StT Separation a :: Type #

Methods

liftWith :: Monad m => (Run Separation -> m a) -> Separation m a #

restoreT :: Monad m => m (StT Separation a) -> Separation m a #

Monad m => Monad (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

(>>=) :: Separation m a -> (a -> Separation m b) -> Separation m b #

(>>) :: Separation m a -> Separation m b -> Separation m b #

return :: a -> Separation m a #

fail :: String -> Separation m a #

Functor m => Functor (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

fmap :: (a -> b) -> Separation m a -> Separation m b #

(<$) :: a -> Separation m b -> Separation m a #

Applicative m => Applicative (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

pure :: a -> Separation m a #

(<*>) :: Separation m (a -> b) -> Separation m a -> Separation m b #

liftA2 :: (a -> b -> c) -> Separation m a -> Separation m b -> Separation m c #

(*>) :: Separation m a -> Separation m b -> Separation m b #

(<*) :: Separation m a -> Separation m b -> Separation m a #

MonadIO m => MonadIO (Separation m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

liftIO :: IO a -> Separation m a #

type StT (Separation :: (Type -> Type) -> Type -> Type) a Source # 
Instance details

Defined in Control.Effect.RWS

type StT (Separation :: (Type -> Type) -> Type -> Type) a = StT (IdentityT :: (Type -> Type) -> Type -> Type) a
type StM (Separation m) a Source # 
Instance details

Defined in Control.Effect.RWS

type StM (Separation m) a = StM m a

runSeparatedRWS' Source #

Arguments

:: ('[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s] `EachVia` Separation) m a

The program whose RWS effect should be handled.

-> m a

The program with its RWS effect handled.

Runs the RWS effect via separation.

runSeparatedRWS :: ('[RWS r w s, Reader r, Writer w, State s] `EachVia` Separation) m a -> m a Source #

The untagged version of runSeparatedRWS'.

Tagging and Untagging

data Tagger tag new m a Source #

The tagging interpreter of the RWS effect. This type implements the RWS' type class by tagging/retagging/untagging its reader, writer and state components.

When interpreting the effect, you usually don't interact with this type directly, but instead use one of its corresponding interpretation functions.

Since: 0.2.0.0

Instances
RWS' new r w s m => RWS' (tag :: k1) r w s (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

RWS' new r w s m => Reader' (tag :: k1) r (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

ask' :: Tagger tag new m r Source #

local' :: (r -> r) -> Tagger tag new m a -> Tagger tag new m a Source #

reader' :: (r -> a) -> Tagger tag new m a Source #

RWS' new r w s m => State' (tag :: k1) s (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

get' :: Tagger tag new m s Source #

put' :: s -> Tagger tag new m () Source #

state' :: (s -> (s, a)) -> Tagger tag new m a Source #

RWS' new r w s m => Writer' (tag :: k1) w (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

tell' :: w -> Tagger tag new m () Source #

listen' :: Tagger tag new m a -> Tagger tag new m (w, a) Source #

censor' :: (w -> w) -> Tagger tag new m a -> Tagger tag new m a Source #

MonadBase b m => MonadBase b (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

liftBase :: b α -> Tagger tag new m α #

MonadBaseControl b m => MonadBaseControl b (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Associated Types

type StM (Tagger tag new m) a :: Type #

Methods

liftBaseWith :: (RunInBase (Tagger tag new m) b -> b a) -> Tagger tag new m a #

restoreM :: StM (Tagger tag new m) a -> Tagger tag new m a #

MonadTrans (Tagger tag new :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

lift :: Monad m => m a -> Tagger tag new m a #

MonadTransControl (Tagger tag new :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Control.Effect.RWS

Associated Types

type StT (Tagger tag new) a :: Type #

Methods

liftWith :: Monad m => (Run (Tagger tag new) -> m a) -> Tagger tag new m a #

restoreT :: Monad m => m (StT (Tagger tag new) a) -> Tagger tag new m a #

Monad m => Monad (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

(>>=) :: Tagger tag new m a -> (a -> Tagger tag new m b) -> Tagger tag new m b #

(>>) :: Tagger tag new m a -> Tagger tag new m b -> Tagger tag new m b #

return :: a -> Tagger tag new m a #

fail :: String -> Tagger tag new m a #

Functor m => Functor (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

fmap :: (a -> b) -> Tagger tag new m a -> Tagger tag new m b #

(<$) :: a -> Tagger tag new m b -> Tagger tag new m a #

Applicative m => Applicative (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

pure :: a -> Tagger tag new m a #

(<*>) :: Tagger tag new m (a -> b) -> Tagger tag new m a -> Tagger tag new m b #

liftA2 :: (a -> b -> c) -> Tagger tag new m a -> Tagger tag new m b -> Tagger tag new m c #

(*>) :: Tagger tag new m a -> Tagger tag new m b -> Tagger tag new m b #

(<*) :: Tagger tag new m a -> Tagger tag new m b -> Tagger tag new m a #

MonadIO m => MonadIO (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.RWS

Methods

liftIO :: IO a -> Tagger tag new m a #

type StT (Tagger tag new :: (Type -> Type) -> Type -> Type) a Source # 
Instance details

Defined in Control.Effect.RWS

type StT (Tagger tag new :: (Type -> Type) -> Type -> Type) a = StT (IdentityT :: (Type -> Type) -> Type -> Type) a
type StM (Tagger tag new m) a Source # 
Instance details

Defined in Control.Effect.RWS

type StM (Tagger tag new m) a = StM m a

Conversion functions between the tagged and untagged RWS effect, usually used in combination with type applications, like:

    tagRWS' @"newTag" program
    retagRWS' @"oldTag" @"newTag" program
    untagRWS' @"erasedTag" program

tagRWS' :: forall new r w s m a. ('[RWS' G r w s, Reader' G r, Writer' G w, State' G s] `EachVia` Tagger G new) m a -> m a Source #

retagRWS' :: forall tag new r w s m a. ('[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s] `EachVia` Tagger tag new) m a -> m a Source #

untagRWS' :: forall tag r w s m a. ('[RWS' tag r w s, Reader' tag r, Writer' tag w, State' tag s] `EachVia` Tagger tag G) m a -> m a Source #