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) # |
Methods writer :: (a, w) -> ReaderT f m a # tell :: w -> ReaderT f m () # listen :: ReaderT f m a -> ReaderT f m (a, w) # pass :: ReaderT f m (a, w -> w) -> ReaderT f m a #
Representable f => MonadTrans (ReaderT f) # |
Methods lift :: Monad m => m a -> ReaderT f m a #
(Representable f, Monad m) => Monad (ReaderT f m) # |
Methods (>>=) :: ReaderT f m a -> (a -> ReaderT f m b) -> ReaderT f m b # (>>) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m b # return :: a -> ReaderT f m a # fail :: String -> ReaderT f m a #
(Functor f, Functor m) => Functor (ReaderT f m) # |
Methods fmap :: (a -> b) -> ReaderT f m a -> ReaderT f m b # (<$) :: a -> ReaderT f m b -> ReaderT f m a #
(Representable f, Applicative m) => Applicative (ReaderT f m) # |
Methods pure :: a -> ReaderT f m a # (<*>) :: ReaderT f m (a -> b) -> ReaderT f m a -> ReaderT f m b # (*>) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m b # (<*) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m a #
(Foldable f, Foldable m) => Foldable (ReaderT f m) # |
Methods fold :: Monoid m => ReaderT f m m -> m # foldMap :: Monoid m => (a -> m) -> ReaderT f m a -> m # foldr :: (a -> b -> b) -> b -> ReaderT f m a -> b # foldr' :: (a -> b -> b) -> b -> ReaderT f m a -> b # foldl :: (b -> a -> b) -> b -> ReaderT f m a -> b # foldl' :: (b -> a -> b) -> b -> ReaderT f m a -> b # foldr1 :: (a -> a -> a) -> ReaderT f m a -> a # foldl1 :: (a -> a -> a) -> ReaderT f m a -> a # toList :: ReaderT f m a -> [a] # null :: ReaderT f m a -> Bool # length :: ReaderT f m a -> Int # elem :: Eq a => a -> ReaderT f m a -> Bool # maximum :: Ord a => ReaderT f m a -> a # minimum :: Ord a => ReaderT f m a -> a # sum :: Num a => ReaderT f m a -> a # product :: Num a => ReaderT f m a -> a #
(Traversable f, Traversable m) => Traversable (ReaderT f m) # |
Methods traverse :: Applicative f => (a -> f b) -> ReaderT f m a -> f (ReaderT f m b) # sequenceA :: Applicative f => ReaderT f m (f a) -> f (ReaderT f m a) # mapM :: Monad m => (a -> m b) -> ReaderT f m a -> m (ReaderT f m b) # sequence :: Monad m => ReaderT f m (m a) -> m (ReaderT f m a) #
(Representable f, MonadIO m) => MonadIO (ReaderT f m) # |
Methods liftIO :: IO a -> ReaderT f m a #
(Representable f, Representable m, Monoid (Rep f), Monoid (Rep m)) => Comonad (ReaderT f m) # |
Methods extract :: ReaderT f m a -> a # duplicate :: ReaderT f m a -> ReaderT f m (ReaderT f m a) # extend :: (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b #
(Representable f, Distributive m) => Distributive (ReaderT f m) # |
Methods distribute :: Functor f => f (ReaderT f m a) -> ReaderT f m (f a) # collect :: Functor f => (a -> ReaderT f m b) -> f a -> ReaderT f m (f b) # distributeM :: Monad m => m (ReaderT f m a) -> ReaderT f m (m a) # collectM :: Monad m => (a -> ReaderT f m b) -> m a -> ReaderT f m (m b) #
(Traversable1 f, Traversable1 m) => Traversable1 (ReaderT f m) # |
Methods traverse1 :: Apply f => (a -> f b) -> ReaderT f m a -> f (ReaderT f m b) # sequence1 :: Apply f => ReaderT f m (f b) -> f (ReaderT f m b) #
(Representable f, Apply m) => Apply (ReaderT f m) # |
Methods (<.>) :: ReaderT f m (a -> b) -> ReaderT f m a -> ReaderT f m b # (.>) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m b # (<.) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m a #
(Representable f, Bind m) => Bind (ReaderT f m) # |
Methods (>>-) :: ReaderT f m a -> (a -> ReaderT f m b) -> ReaderT f m b # join :: ReaderT f m (ReaderT f m a) -> ReaderT f m a #
(Representable f, Representable m, Semigroup (Rep f), Semigroup (Rep m)) => Extend (ReaderT f m) # |
Methods duplicated :: ReaderT f m a -> ReaderT f m (ReaderT f m a) # extended :: (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b #
(Foldable1 f, Foldable1 m) => Foldable1 (ReaderT f m) # |
Methods fold1 :: Semigroup m => ReaderT f m m -> m # foldMap1 :: Semigroup m => (a -> m) -> ReaderT f m a -> m #
(Representable f, Representable m) => Representable (ReaderT f m) # |
Associated Types type Rep (ReaderT f m :: * -> *) :: * # Methods tabulate :: (Rep (ReaderT f m) -> a) -> ReaderT f m a # index :: ReaderT f m a -> Rep (ReaderT f m) -> a #
type Rep (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

Instances

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

module Data.Functor.Rep