effet-0.1.0.0: 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.Reader

Description

The reader effect, similar to the MonadReader type class from the mtl library.

Synopsis

Tagged Reader Effect

class Monad m => Reader' tag r m | tag m -> r where Source #

An effect that adds an immutable state (i.e., an "environment") to a given computation. The effect allows to read values from the environment, pass values from function to function, and execute sub-computations in a modified environment.

Minimal complete definition

(ask' | reader'), local'

Methods

ask' :: m r Source #

Gets the environment.

local' Source #

Arguments

:: (r -> r)

The function to modify the environment.

-> m a

The sub-computation to run in the modified environment.

-> m a

The result of the sub-computation.

Executes a sub-computation in a modified environment.

reader' Source #

Arguments

:: (r -> a)

The projection function to apply to the environment.

-> m a

The result of the projection.

Gets a specific component of the environment, using the provided projection function.

Instances

Instances details
Monad m => Reader' (tag :: k) r (ReaderT r m) Source # 
Instance details

Defined in Control.Effect.Reader

Methods

ask' :: ReaderT r m r Source #

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

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

Control (Reader' tag r) t m => Reader' (tag :: k) r (Via eff t m) Source # 
Instance details

Defined in Control.Effect.Reader

Methods

ask' :: Via eff t m r Source #

local' :: (r -> r) -> Via eff t m a -> Via eff t m a Source #

reader' :: (r -> a) -> Via eff t m a Source #

Handle (Reader' tag r) t m => Reader' (tag :: k) r (Via (Reader' tag r) t m) Source # 
Instance details

Defined in Control.Effect.Reader

Methods

ask' :: Via (Reader' tag r) t m r Source #

local' :: (r -> r) -> Via (Reader' tag r) t m a -> Via (Reader' tag r) t m a Source #

reader' :: (r -> a) -> Via (Reader' tag r) t m a Source #

Reader' new r m => Reader' (tag :: k2) r (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.Reader

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 #

Untagged Reader Effect

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

type Reader r = Reader' G r Source #

ask :: Reader r m => m r Source #

local :: Reader r m => (r -> r) -> m a -> m a Source #

reader :: Reader r m => (r -> a) -> m a Source #

Convenience Functions

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

asks' Source #

Arguments

:: forall tag r m a. Reader' tag r m 
=> (r -> a)

The projection function to apply to the environment.

-> m a

The result of the projection.

Gets a specific component of the environment, using the provided projection function.

asks :: Reader r m => (r -> a) -> m a Source #

The untagged version of asks'.

Interpretations

runReader' Source #

Arguments

:: forall tag r m a. r

The initial environment.

-> (Reader' tag r `Via` ReaderT r) m a

The program whose reader effect should be handled.

-> m a

The program with its reader effect handled.

Runs the reader effect.

runReader :: r -> (Reader r `Via` ReaderT r) m a -> m a Source #

The untagged version of runReader'.

Tagging and Untagging

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

    tagReader' @"newTag" program
    retagReader' @"oldTag" @"newTag" program
    untagReader' @"erasedTag" program

tagReader' :: forall new r m a. Via (Reader' G r) (Tagger G new) m a -> m a Source #

retagReader' :: forall tag new r m a. Via (Reader' tag r) (Tagger tag new) m a -> m a Source #

untagReader' :: forall tag r m a. Via (Reader' tag r) (Tagger tag G) m a -> m a Source #