adjunctions-4.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 | Safe-Inferred
Language | Haskell2010

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 :: Type -> Type) = ReaderT f Identity
- runReader :: forall (f :: Type -> Type) b. Representable f => Reader f b -> Rep f -> b
- newtype ReaderT (f :: Type -> Type) (m :: Type -> Type) b = ReaderT {
  - getReaderT :: f (m b)
  }
- readerT :: forall (f :: Type -> Type) m b. Representable f => (Rep f -> m b) -> ReaderT f m b
- runReaderT :: forall (f :: Type -> Type) m b. Representable f => ReaderT f m b -> Rep f -> m b
- class Monad m => MonadReader r (m :: Type -> Type) | 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 :: Type -> Type) = ReaderT f Identity Source #

runReader :: forall (f :: Type -> Type) b. Representable f => Reader f b -> Rep f -> b Source #

# Monad Transformer

newtype ReaderT (f :: Type -> Type) (m :: Type -> Type) b Source #

Constructors

ReaderT |

Fields

- getReaderT :: f (m b)

#### Instances

Instances details

(Representable f, Monad m, Rep f ~ e) => MonadReader e (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods ask :: ReaderT f m e Source # local :: (e -> e) -> ReaderT f m a -> ReaderT f m a Source # reader :: (e -> a) -> ReaderT f m a Source #
(Representable f, MonadWriter w m) => MonadWriter w (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods writer :: (a, w) -> ReaderT f m a Source # tell :: w -> ReaderT f m () Source # listen :: ReaderT f m a -> ReaderT f m (a, w) Source # pass :: ReaderT f m (a, w -> w) -> ReaderT f m a Source #
Representable f => MonadTrans (ReaderT f) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods lift :: Monad m => m a -> ReaderT f m a Source #
(Representable f, Representable m) => Representable (ReaderT f m) Source # |

Instance details

Defined in Control.Monad.Representable.Reader

Associated Types

type Rep (ReaderT f m) |
Instance details Defined in Control.Monad.Representable.Reader type Rep (ReaderT f m) = (Rep f, Rep m)

Methods

tabulate :: (Rep (ReaderT f m) -> a) -> ReaderT f m a Source #

index :: ReaderT f m a -> Rep (ReaderT f m) -> a Source #

(Representable f, MonadIO m) => MonadIO (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods liftIO :: IO a -> ReaderT f m a Source #
(Foldable1 f, Foldable1 m) => Foldable1 (ReaderT f m) Source # |

Instance details

Defined in Control.Monad.Representable.Reader

Methods

fold1 :: Semigroup m0 => ReaderT f m m0 -> m0 Source #

foldMap1 :: Semigroup m0 => (a -> m0) -> ReaderT f m a -> m0 Source #

foldMap1' :: Semigroup m0 => (a -> m0) -> ReaderT f m a -> m0 Source #

toNonEmpty :: ReaderT f m a -> NonEmpty a Source #

maximum :: Ord a => ReaderT f m a -> a Source #

minimum :: Ord a => ReaderT f m a -> a Source #

head :: ReaderT f m a -> a Source #

last :: ReaderT f m a -> a Source #

foldrMap1 :: (a -> b) -> (a -> b -> b) -> ReaderT f m a -> b Source #

foldlMap1' :: (a -> b) -> (b -> a -> b) -> ReaderT f m a -> b Source #

foldlMap1 :: (a -> b) -> (b -> a -> b) -> ReaderT f m a -> b Source #

foldrMap1' :: (a -> b) -> (a -> b -> b) -> ReaderT f m a -> b Source #

(Representable f, Representable m, Monoid (Rep f), Monoid (Rep m)) => Comonad (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods extract :: ReaderT f m a -> a Source # duplicate :: ReaderT f m a -> ReaderT f m (ReaderT f m a) Source # extend :: (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b Source #
(Representable f, Distributive m) => Distributive (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods distribute :: Functor f0 => f0 (ReaderT f m a) -> ReaderT f m (f0 a) Source # collect :: Functor f0 => (a -> ReaderT f m b) -> f0 a -> ReaderT f m (f0 b) Source # distributeM :: Monad m0 => m0 (ReaderT f m a) -> ReaderT f m (m0 a) Source # collectM :: Monad m0 => (a -> ReaderT f m b) -> m0 a -> ReaderT f m (m0 b) Source #
(Representable f, Applicative m) => Applicative (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods pure :: a -> ReaderT f m a Source # (<*>) :: ReaderT f m (a -> b) -> ReaderT f m a -> ReaderT f m b Source # liftA2 :: (a -> b -> c) -> ReaderT f m a -> ReaderT f m b -> ReaderT f m c Source # (*>) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m b Source # (<*) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m a Source #
(Functor f, Functor m) => Functor (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods fmap :: (a -> b) -> ReaderT f m a -> ReaderT f m b Source # (<$) :: a -> ReaderT f m b -> ReaderT f m a Source #
(Representable f, Monad m) => Monad (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods (>>=) :: ReaderT f m a -> (a -> ReaderT f m b) -> ReaderT f m b Source # (>>) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m b Source # return :: a -> ReaderT f m a Source #
(Foldable f, Foldable m) => Foldable (ReaderT f m) Source # |

Instance details

Defined in Control.Monad.Representable.Reader

Methods

fold :: Monoid m0 => ReaderT f m m0 -> m0 Source #

foldMap :: Monoid m0 => (a -> m0) -> ReaderT f m a -> m0 Source #

foldMap' :: Monoid m0 => (a -> m0) -> ReaderT f m a -> m0 Source #

foldr :: (a -> b -> b) -> b -> ReaderT f m a -> b Source #

foldr' :: (a -> b -> b) -> b -> ReaderT f m a -> b Source #

foldl :: (b -> a -> b) -> b -> ReaderT f m a -> b Source #

foldl' :: (b -> a -> b) -> b -> ReaderT f m a -> b Source #

foldr1 :: (a -> a -> a) -> ReaderT f m a -> a Source #

foldl1 :: (a -> a -> a) -> ReaderT f m a -> a Source #

toList :: ReaderT f m a -> [a] Source #

null :: ReaderT f m a -> Bool Source #

length :: ReaderT f m a -> Int Source #

elem :: Eq a => a -> ReaderT f m a -> Bool Source #

maximum :: Ord a => ReaderT f m a -> a Source #

minimum :: Ord a => ReaderT f m a -> a Source #

sum :: Num a => ReaderT f m a -> a Source #

product :: Num a => ReaderT f m a -> a Source #

(Traversable f, Traversable m) => Traversable (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods traverse :: Applicative f0 => (a -> f0 b) -> ReaderT f m a -> f0 (ReaderT f m b) Source # sequenceA :: Applicative f0 => ReaderT f m (f0 a) -> f0 (ReaderT f m a) Source # mapM :: Monad m0 => (a -> m0 b) -> ReaderT f m a -> m0 (ReaderT f m b) Source # sequence :: Monad m0 => ReaderT f m (m0 a) -> m0 (ReaderT f m a) Source #
(Representable f, Apply m) => Apply (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods (<.>) :: ReaderT f m (a -> b) -> ReaderT f m a -> ReaderT f m b Source # (.>) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m b Source # (<.) :: ReaderT f m a -> ReaderT f m b -> ReaderT f m a Source # liftF2 :: (a -> b -> c) -> ReaderT f m a -> ReaderT f m b -> ReaderT f m c Source #
(Representable f, Bind m) => Bind (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods (>>-) :: ReaderT f m a -> (a -> ReaderT f m b) -> ReaderT f m b Source # join :: ReaderT f m (ReaderT f m a) -> ReaderT f m a Source #
(Representable f, Representable m, Semigroup (Rep f), Semigroup (Rep m)) => Extend (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods duplicated :: ReaderT f m a -> ReaderT f m (ReaderT f m a) Source # extended :: (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b Source #
(Traversable1 f, Traversable1 m) => Traversable1 (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods traverse1 :: Apply f0 => (a -> f0 b) -> ReaderT f m a -> f0 (ReaderT f m b) Source # sequence1 :: Apply f0 => ReaderT f m (f0 b) -> f0 (ReaderT f m b) Source #
type Rep (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader type Rep (ReaderT f m) = (Rep f, Rep m)

readerT :: forall (f :: Type -> Type) m b. Representable f => (Rep f -> m b) -> ReaderT f m b Source #

runReaderT :: forall (f :: Type -> Type) m b. Representable f => ReaderT f m b -> Rep f -> m b Source #

class Monad m => MonadReader r (m :: Type -> Type) | m -> r where Source #

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

Retrieves the monad environment.

local Source #

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

Arguments

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

Retrieves a function of the current environment.

#### Instances

Instances details

(Representable f, Rep f ~ a) => MonadReader a (Co f) Source # |
Instance details Defined in Data.Functor.Rep Methods ask :: Co f a Source # local :: (a -> a) -> Co f a0 -> Co f a0 Source # reader :: (a -> a0) -> Co f a0 Source #
MonadReader e m => MonadReader e (Free m) |
Instance details Defined in Control.Monad.Free Methods ask :: Free m e Source # local :: (e -> e) -> Free m a -> Free m a Source # reader :: (e -> a) -> Free m a Source #
MonadReader e m => MonadReader e (Free m) |
Instance details Defined in Control.Monad.Free.Ap Methods ask :: Free m e Source # local :: (e -> e) -> Free m a -> Free m a Source # reader :: (e -> a) -> Free m a Source #
MonadReader e m => MonadReader e (F m) |
Instance details Defined in Control.Monad.Free.Church Methods ask :: F m e Source # local :: (e -> e) -> F m a -> F m a Source # reader :: (e -> a) -> F m a Source #
MonadReader e m => MonadReader e (IterT m) |
Instance details Defined in Control.Monad.Trans.Iter Methods ask :: IterT m e Source # local :: (e -> e) -> IterT m a -> IterT m a Source # reader :: (e -> a) -> IterT m a Source #
MonadReader r m => MonadReader r (MaybeT m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: MaybeT m r Source # local :: (r -> r) -> MaybeT m a -> MaybeT m a Source # reader :: (r -> a) -> MaybeT m a Source #
(Representable f, Monad m, Rep f ~ e) => MonadReader e (ReaderT f m) Source # |
Instance details Defined in Control.Monad.Representable.Reader Methods ask :: ReaderT f m e Source # local :: (e -> e) -> ReaderT f m a -> ReaderT f m a Source # reader :: (e -> a) -> ReaderT f m a Source #
(Representable g, MonadReader e m) => MonadReader e (StateT g m) Source # |
Instance details Defined in Control.Monad.Representable.State Methods ask :: StateT g m e Source # local :: (e -> e) -> StateT g m a -> StateT g m a Source # reader :: (e -> a) -> StateT g m a Source #
(Functor f, MonadReader r m) => MonadReader r (FreeT f m) |
Instance details Defined in Control.Monad.Trans.Free Methods ask :: FreeT f m r Source # local :: (r -> r) -> FreeT f m a -> FreeT f m a Source # reader :: (r -> a) -> FreeT f m a Source #
(Applicative f, MonadReader r m) => MonadReader r (FreeT f m) |
Instance details Defined in Control.Monad.Trans.Free.Ap Methods ask :: FreeT f m r Source # local :: (r -> r) -> FreeT f m a -> FreeT f m a Source # reader :: (r -> a) -> FreeT f m a Source #
MonadReader r m => MonadReader r (FT f m) |
Instance details Defined in Control.Monad.Trans.Free.Church Methods ask :: FT f m r Source # local :: (r -> r) -> FT f m a -> FT f m a Source # reader :: (r -> a) -> FT f m a Source #
(Monoid w, MonadReader r m) => MonadReader r (AccumT w m) | Since: mtl-2.3
Instance details Defined in Control.Monad.Reader.Class Methods ask :: AccumT w m r Source # local :: (r -> r) -> AccumT w m a -> AccumT w m a Source # reader :: (r -> a) -> AccumT w m a Source #
MonadReader r m => MonadReader r (ExceptT e m) | Since: mtl-2.2
Instance details Defined in Control.Monad.Reader.Class Methods ask :: ExceptT e m r Source # local :: (r -> r) -> ExceptT e m a -> ExceptT e m a Source # reader :: (r -> a) -> ExceptT e m a Source #
MonadReader r m => MonadReader r (IdentityT m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: IdentityT m r Source # local :: (r -> r) -> IdentityT m a -> IdentityT m a Source # reader :: (r -> a) -> IdentityT m a Source #
Monad m => MonadReader r (ReaderT r m) |
Instance details Defined in Control.Monad.Reader.Class 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 #
MonadReader r m => MonadReader r (StateT s m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: StateT s m r Source # local :: (r -> r) -> StateT s m a -> StateT s m a Source # reader :: (r -> a) -> StateT s m a Source #
MonadReader r m => MonadReader r (StateT s m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: StateT s m r Source # local :: (r -> r) -> StateT s m a -> StateT s m a Source # reader :: (r -> a) -> StateT s m a Source #
(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | Since: mtl-2.3
Instance details Defined in Control.Monad.Reader.Class Methods ask :: WriterT w m r Source # local :: (r -> r) -> WriterT w m a -> WriterT w m a Source # reader :: (r -> a) -> WriterT w m a Source #
(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: WriterT w m r Source # local :: (r -> r) -> WriterT w m a -> WriterT w m a Source # reader :: (r -> a) -> WriterT w m a Source #
(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: WriterT w m r Source # local :: (r -> r) -> WriterT w m a -> WriterT w m a Source # reader :: (r -> a) -> WriterT w m a Source #
MonadReader r' m => MonadReader r' (SelectT r m) | Since: mtl-2.3
Instance details Defined in Control.Monad.Reader.Class Methods ask :: SelectT r m r' Source # local :: (r' -> r') -> SelectT r m a -> SelectT r m a Source # reader :: (r' -> a) -> SelectT r m a Source #
MonadReader r ((->) r) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: r -> r Source # local :: (r -> r) -> (r -> a) -> r -> a Source # reader :: (r -> a) -> r -> a Source #
MonadReader r' m => MonadReader r' (ContT r m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: ContT r m r' Source # local :: (r' -> r') -> ContT r m a -> ContT r m a Source # reader :: (r' -> a) -> ContT r m a Source #
(Monad m, Monoid w) => MonadReader r (RWST r w s m) | Since: mtl-2.3
Instance details Defined in Control.Monad.Reader.Class Methods ask :: RWST r w s m r Source # local :: (r -> r) -> RWST r w s m a -> RWST r w s m a Source # reader :: (r -> a) -> RWST r w s m a Source #
(Monad m, Monoid w) => MonadReader r (RWST r w s m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: RWST r w s m r Source # local :: (r -> r) -> RWST r w s m a -> RWST r w s m a Source # reader :: (r -> a) -> RWST r w s m a Source #
(Monad m, Monoid w) => MonadReader r (RWST r w s m) |
Instance details Defined in Control.Monad.Reader.Class Methods ask :: RWST r w s m r Source # local :: (r -> r) -> RWST r w s m a -> RWST r w s m a Source # reader :: (r -> a) -> RWST r w s m a Source #

module Data.Functor.Rep