Control.Monad.Representable.Reader

adjunctions-4.3: Adjunctions and representable functors

Copyright | (c) Edward Kmett 2011, (c) Conal Elliott 2008
License | BSD3
Maintainer | ekmett@gmail.com
Stability | experimental
Safe Haskell | None
Language | Haskell98

Control.Monad.Representable.Reader

Contents

- Representable functor monad
- Monad Transformer

Description

Representable functors on Hask are all monads, because they are isomorphic to a `Reader` monad.

Synopsis

- type Reader f = ReaderT f Identity
- runReader :: Representable f => Reader f b -> Rep f -> b
- newtype ReaderT f m b = ReaderT {
  - getReaderT :: f (m b)
  }
- readerT :: Representable f => (Rep f -> m b) -> ReaderT f m b
- runReaderT :: Representable f => ReaderT f m b -> Rep f -> m b
- class Monad m => MonadReader r m | m -> r where
  - ask :: m r
  - local :: (r -> r) -> m a -> m a
  - reader :: (r -> a) -> m a
- module Data.Functor.Rep

# Representable functor monad

type Reader f = ReaderT f Identity

runReader :: Representable f => Reader f b -> Rep f -> b

# Monad Transformer

newtype ReaderT f m b

Constructors

ReaderT |
Fields getReaderT :: f (m b)

Instances

(Representable f, MonadWriter w m) => MonadWriter w (ReaderT f m) |
Representable f => MonadTrans (ReaderT f) |
(Representable f, Monad m) => Monad (ReaderT f m) |
(Functor f, Functor m) => Functor (ReaderT f m) |
(Representable f, Applicative m) => Applicative (ReaderT f m) |
(Foldable f, Foldable m) => Foldable (ReaderT f m) |
(Traversable f, Traversable m) => Traversable (ReaderT f m) |
(Representable f, Representable m, Monoid (Rep f), Monoid (Rep m)) => Comonad (ReaderT f m) |
(Representable f, Distributive m) => Distributive (ReaderT f m) |
(Representable f, MonadIO m) => MonadIO (ReaderT f m) |
(Traversable1 f, Traversable1 m) => Traversable1 (ReaderT f m) |
(Representable f, Apply m) => Apply (ReaderT f m) |
(Representable f, Bind m) => Bind (ReaderT f m) |
(Representable f, Representable m, Semigroup (Rep f), Semigroup (Rep m)) => Extend (ReaderT f m) |
(Foldable1 f, Foldable1 m) => Foldable1 (ReaderT f m) |
(Representable f, Representable m) => Representable (ReaderT f m) |
type Rep (ReaderT f m) = (Rep f, Rep m) |

readerT :: Representable f => (Rep f -> m b) -> ReaderT f m b

runReaderT :: Representable f => ReaderT f m b -> Rep f -> m b

class Monad m => MonadReader r m | m -> r where

See examples in Control.Monad.Reader. Note, the partially applied function type `(->) r` is a simple reader monad. See the `instance` declaration below.

Minimal complete definition

(ask | reader), local

Methods

ask :: m r

Retrieves the monad environment.

local

Arguments

:: (r -> r) | The function to modify the environment.
-> m a | `Reader` to run in the modified environment.
-> m a |

Executes a computation in a modified environment.

reader

Arguments

:: (r -> a) | The selector function to apply to the environment.
-> m a |

Retrieves a function of the current environment.

Instances

(Representable f, (~) * (Rep f) a) => MonadReader a (Co f) |
MonadReader r m => MonadReader r (MaybeT m) |
MonadReader r m => MonadReader r (ListT m) |
MonadReader r m => MonadReader r (IdentityT m) |
MonadReader r ((->) r) |
(Functor m, MonadReader e m) => MonadReader e (Free m) |
(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) |
(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) |
MonadReader r m => MonadReader r (StateT s m) |
MonadReader r m => MonadReader r (StateT s m) |
Monad m => MonadReader r (ReaderT r m) |
MonadReader r m => MonadReader r (ExceptT e m) |
(Error e, MonadReader r m) => MonadReader r (ErrorT e m) |
MonadReader r' m => MonadReader r' (ContT r m) |
(Representable g, MonadReader e m) => MonadReader e (StateT g m) |
(Monad m, Monoid w) => MonadReader r (RWST r w s m) |
(Monad m, Monoid w) => MonadReader r (RWST r w s m) |

module Data.Functor.Rep