    {-# LANGUAGE GADTs, TypeFamilies, TypeOperators, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances, TypeSynonymInstances #-}
    {-# OPTIONS_GHC -fenable-rewrite-rules -Wno-orphans #-}
    ----------------------------------------------------------------------
    -- |
    -- Module      :  Control.Monad.Representable.Reader
    -- Copyright   :  (c) Edward Kmett 2011,
    --                (c) Conal Elliott 2008
    -- License     :  BSD3
    --
    -- Maintainer  :  ekmett@gmail.com
    -- Stability   :  experimental
    --
    -- Representable functors on Hask are all monads, because they are isomorphic to
    -- a 'Reader' monad.
    ----------------------------------------------------------------------

    module Control.Monad.Representable.Reader
      (
      -- * Representable functor monad
        Reader
      , runReader
      -- * Monad Transformer
      , ReaderT(..), readerT, runReaderT
      , MonadReader(..)
      , module Data.Functor.Rep
      ) where

    import Control.Applicative
    import Control.Comonad
    import Control.Monad.Reader.Class
    import Control.Monad.Writer.Class as Writer
    import Control.Monad.Trans.Class
    import Control.Monad.IO.Class
    import Data.Distributive
    import Data.Functor.Bind
    import Data.Functor.Extend
    import Data.Functor.Identity
    import Data.Functor.Rep
    import Data.Foldable
    import Data.Traversable
    import Data.Semigroup
    import Data.Semigroup.Foldable
    import Data.Semigroup.Traversable
    import Prelude hiding (lookup,zipWith)

    type Reader f = ReaderT f Identity

    runReader :: Representable f => Reader f b -> Rep f -> b
    runReader :: forall (f :: * -> *) b. Representable f => Reader f b -> Rep f -> b
    runReader = (Identity b -> b) -> (Rep f -> Identity b) -> Rep f -> b
    forall a b. (a -> b) -> (Rep f -> a) -> Rep f -> b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Identity b -> b
    forall a. Identity a -> a
    runIdentity ((Rep f -> Identity b) -> Rep f -> b)
    -> (Reader f b -> Rep f -> Identity b) -> Reader f b -> Rep f -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Reader f b -> Rep f -> Identity b
    forall (f :: * -> *) (m :: * -> *) b.
    Representable f =>
    ReaderT f m b -> Rep f -> m b
    runReaderT

    -- * This 'representable monad transformer' transforms any monad @m@ with a 'Representable' 'Monad'.
    --   This monad in turn is also representable if @m@ is 'Representable'.
    newtype ReaderT f m b = ReaderT { forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT :: f (m b) }

    readerT :: Representable f => (Rep f -> m b) -> ReaderT f m b
    readerT :: forall (f :: * -> *) (m :: * -> *) b.
    Representable f =>
    (Rep f -> m b) -> ReaderT f m b
    readerT = f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m b) -> ReaderT f m b)
    -> ((Rep f -> m b) -> f (m b)) -> (Rep f -> m b) -> ReaderT f m b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Rep f -> m b) -> f (m b)
    forall a. (Rep f -> a) -> f a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate

    runReaderT :: Representable f => ReaderT f m b -> Rep f -> m b
    runReaderT :: forall (f :: * -> *) (m :: * -> *) b.
    Representable f =>
    ReaderT f m b -> Rep f -> m b
    runReaderT = f (m b) -> Rep f -> m b
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index (f (m b) -> Rep f -> m b)
    -> (ReaderT f m b -> f (m b)) -> ReaderT f m b -> Rep f -> m b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m b -> f (m b)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT

    instance (Functor f, Functor m) => Functor (ReaderT f m) where
      fmap :: forall a b. (a -> b) -> ReaderT f m a -> ReaderT f m b
    fmap a -> b
    f = f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m b) -> ReaderT f m b)
    -> (ReaderT f m a -> f (m b)) -> ReaderT f m a -> ReaderT f m b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (m a -> m b) -> f (m a) -> f (m b)
    forall a b. (a -> b) -> f a -> f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((a -> b) -> m a -> m b
    forall a b. (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    f) (f (m a) -> f (m b))
    -> (ReaderT f m a -> f (m a)) -> ReaderT f m a -> f (m b)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m a -> f (m a)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT

    instance (Representable f, Representable m) => Representable (ReaderT f m) where
      type Rep (ReaderT f m) = (Rep f, Rep m)
      tabulate :: forall a. (Rep (ReaderT f m) -> a) -> ReaderT f m a
    tabulate = f (m a) -> ReaderT f m a
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m a) -> ReaderT f m a)
    -> (((Rep f, Rep m) -> a) -> f (m a))
    -> ((Rep f, Rep m) -> a)
    -> ReaderT f m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Rep f -> m a) -> f (m a)
    forall a. (Rep f -> a) -> f a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate ((Rep f -> m a) -> f (m a))
    -> (((Rep f, Rep m) -> a) -> Rep f -> m a)
    -> ((Rep f, Rep m) -> a)
    -> f (m a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Rep m -> a) -> m a) -> (Rep f -> Rep m -> a) -> Rep f -> m a
    forall a b. (a -> b) -> (Rep f -> a) -> Rep f -> b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Rep m -> a) -> m a
    forall a. (Rep m -> a) -> m a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate ((Rep f -> Rep m -> a) -> Rep f -> m a)
    -> (((Rep f, Rep m) -> a) -> Rep f -> Rep m -> a)
    -> ((Rep f, Rep m) -> a)
    -> Rep f
    -> m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Rep f, Rep m) -> a) -> Rep f -> Rep m -> a
    forall a b c. ((a, b) -> c) -> a -> b -> c
    curry
      index :: forall a. ReaderT f m a -> Rep (ReaderT f m) -> a
    index = (Rep f -> Rep m -> a) -> (Rep f, Rep m) -> a
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry ((Rep f -> Rep m -> a) -> (Rep f, Rep m) -> a)
    -> (ReaderT f m a -> Rep f -> Rep m -> a)
    -> ReaderT f m a
    -> (Rep f, Rep m)
    -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (m a -> Rep m -> a) -> (Rep f -> m a) -> Rep f -> Rep m -> a
    forall a b. (a -> b) -> (Rep f -> a) -> Rep f -> b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap m a -> Rep m -> a
    forall a. m a -> Rep m -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index ((Rep f -> m a) -> Rep f -> Rep m -> a)
    -> (ReaderT f m a -> Rep f -> m a)
    -> ReaderT f m a
    -> Rep f
    -> Rep m
    -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . f (m a) -> Rep f -> m a
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index (f (m a) -> Rep f -> m a)
    -> (ReaderT f m a -> f (m a)) -> ReaderT f m a -> Rep f -> m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m a -> f (m a)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT

    instance (Representable f, Apply m) => Apply (ReaderT f m) where
      ReaderT f (m (a -> b))
    ff <.> :: forall a b. ReaderT f m (a -> b) -> ReaderT f m a -> ReaderT f m b
    <.> ReaderT f (m a)
    fa = f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (Co f (m b) -> f (m b)
    forall (f :: * -> *) a. Co f a -> f a
    unCo (m (a -> b) -> m a -> m b
    forall a b. m (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
    (<.>) (m (a -> b) -> m a -> m b)
    -> Co f (m (a -> b)) -> Co f (m a -> m b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> f (m (a -> b)) -> Co f (m (a -> b))
    forall (f :: * -> *) a. f a -> Co f a
    Co f (m (a -> b))
    ff Co f (m a -> m b) -> Co f (m a) -> Co f (m b)
    forall a b. Co f (a -> b) -> Co f a -> Co f b
    forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
    <.> f (m a) -> Co f (m a)
    forall (f :: * -> *) a. f a -> Co f a
    Co f (m a)
    fa))

    instance (Representable f, Applicative m) => Applicative (ReaderT f m) where
      pure :: forall a. a -> ReaderT f m a
    pure = f (m a) -> ReaderT f m a
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m a) -> ReaderT f m a) -> (a -> f (m a)) -> a -> ReaderT f m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m a -> f (m a)
    forall (f :: * -> *) a. Representable f => a -> f a
    pureRep (m a -> f (m a)) -> (a -> m a) -> a -> f (m a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> m a
    forall a. a -> m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure
      ReaderT f (m (a -> b))
    ff <*> :: forall a b. ReaderT f m (a -> b) -> ReaderT f m a -> ReaderT f m b
    <*> ReaderT f (m a)
    fa = f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (Co f (m b) -> f (m b)
    forall (f :: * -> *) a. Co f a -> f a
    unCo (m (a -> b) -> m a -> m b
    forall a b. m (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    (<*>) (m (a -> b) -> m a -> m b)
    -> Co f (m (a -> b)) -> Co f (m a -> m b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> f (m (a -> b)) -> Co f (m (a -> b))
    forall (f :: * -> *) a. f a -> Co f a
    Co f (m (a -> b))
    ff Co f (m a -> m b) -> Co f (m a) -> Co f (m b)
    forall a b. Co f (a -> b) -> Co f a -> Co f b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> f (m a) -> Co f (m a)
    forall (f :: * -> *) a. f a -> Co f a
    Co f (m a)
    fa))

    instance (Representable f, Bind m) => Bind (ReaderT f m) where
      ReaderT f (m a)
    fm >>- :: forall a b. ReaderT f m a -> (a -> ReaderT f m b) -> ReaderT f m b
    >>- a -> ReaderT f m b
    f = f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m b) -> ReaderT f m b) -> f (m b) -> ReaderT f m b
    forall a b. (a -> b) -> a -> b
    $ (Rep f -> m b) -> f (m b)
    forall a. (Rep f -> a) -> f a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate (\Rep f
    a -> f (m a) -> Rep f -> m a
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index f (m a)
    fm Rep f
    a m a -> (a -> m b) -> m b
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
    >>- (f (m b) -> Rep f -> m b) -> Rep f -> f (m b) -> m b
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip f (m b) -> Rep f -> m b
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index Rep f
    a (f (m b) -> m b) -> (a -> f (m b)) -> a -> m b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m b -> f (m b)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT (ReaderT f m b -> f (m b)) -> (a -> ReaderT f m b) -> a -> f (m b)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> ReaderT f m b
    f)

    instance (Representable f, Monad m) => Monad (ReaderT f m) where
      ReaderT f (m a)
    fm >>= :: forall a b. ReaderT f m a -> (a -> ReaderT f m b) -> ReaderT f m b
    >>= a -> ReaderT f m b
    f = f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m b) -> ReaderT f m b) -> f (m b) -> ReaderT f m b
    forall a b. (a -> b) -> a -> b
    $ (Rep f -> m b) -> f (m b)
    forall a. (Rep f -> a) -> f a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate (\Rep f
    a -> f (m a) -> Rep f -> m a
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index f (m a)
    fm Rep f
    a m a -> (a -> m b) -> m b
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (f (m b) -> Rep f -> m b) -> Rep f -> f (m b) -> m b
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip f (m b) -> Rep f -> m b
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index Rep f
    a (f (m b) -> m b) -> (a -> f (m b)) -> a -> m b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m b -> f (m b)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT (ReaderT f m b -> f (m b)) -> (a -> ReaderT f m b) -> a -> f (m b)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> ReaderT f m b
    f)

    instance (Representable f, Monad m, Rep f ~ e) => MonadReader e (ReaderT f m) where
      ask :: ReaderT f m e
    ask = f (m e) -> ReaderT f m e
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT ((Rep f -> m e) -> f (m e)
    forall a. (Rep f -> a) -> f a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate e -> m e
    Rep f -> m e
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return)
      local :: forall a. (e -> e) -> ReaderT f m a -> ReaderT f m a
    local e -> e
    f ReaderT f m a
    m = (Rep f -> m a) -> ReaderT f m a
    forall (f :: * -> *) (m :: * -> *) b.
    Representable f =>
    (Rep f -> m b) -> ReaderT f m b
    readerT ((Rep f -> m a) -> ReaderT f m a)
    -> (Rep f -> m a) -> ReaderT f m a
    forall a b. (a -> b) -> a -> b
    $ \Rep f
    r -> ReaderT f m a -> Rep f -> m a
    forall (f :: * -> *) (m :: * -> *) b.
    Representable f =>
    ReaderT f m b -> Rep f -> m b
    runReaderT ReaderT f m a
    m (e -> e
    f e
    Rep f
    r)
      reader :: forall a. (e -> a) -> ReaderT f m a
    reader = (e -> m a) -> ReaderT f m a
    (Rep f -> m a) -> ReaderT f m a
    forall (f :: * -> *) (m :: * -> *) b.
    Representable f =>
    (Rep f -> m b) -> ReaderT f m b
    readerT ((e -> m a) -> ReaderT f m a)
    -> ((e -> a) -> e -> m a) -> (e -> a) -> ReaderT f m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> m a) -> (e -> a) -> e -> m a
    forall a b. (a -> b) -> (e -> a) -> e -> b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> m a
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return

    instance Representable f => MonadTrans (ReaderT f) where
      lift :: forall (m :: * -> *) a. Monad m => m a -> ReaderT f m a
    lift = f (m a) -> ReaderT f m a
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m a) -> ReaderT f m a)
    -> (m a -> f (m a)) -> m a -> ReaderT f m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m a -> f (m a)
    forall (f :: * -> *) a. Representable f => a -> f a
    pureRep

    instance (Representable f, Distributive m) => Distributive (ReaderT f m) where
      distribute :: forall (f :: * -> *) a.
    Functor f =>
    f (ReaderT f m a) -> ReaderT f m (f a)
    distribute = f (m (f a)) -> ReaderT f m (f a)
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m (f a)) -> ReaderT f m (f a))
    -> (f (ReaderT f m a) -> f (m (f a)))
    -> f (ReaderT f m a)
    -> ReaderT f m (f a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (f (m a) -> m (f a)) -> f (f (m a)) -> f (m (f a))
    forall (f :: * -> *) a b. Representable f => (a -> b) -> f a -> f b
    fmapRep f (m a) -> m (f a)
    forall (g :: * -> *) (f :: * -> *) a.
    (Distributive g, Functor f) =>
    f (g a) -> g (f a)
    forall (f :: * -> *) a. Functor f => f (m a) -> m (f a)
    distribute (f (f (m a)) -> f (m (f a)))
    -> (f (ReaderT f m a) -> f (f (m a)))
    -> f (ReaderT f m a)
    -> f (m (f a))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Co f (f (m a)) -> f (f (m a))
    forall (f :: * -> *) a. Co f a -> f a
    unCo (Co f (f (m a)) -> f (f (m a)))
    -> (f (ReaderT f m a) -> Co f (f (m a)))
    -> f (ReaderT f m a)
    -> f (f (m a))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ReaderT f m a -> Co f (m a))
    -> f (ReaderT f m a) -> Co f (f (m a))
    forall (g :: * -> *) (f :: * -> *) a b.
    (Distributive g, Functor f) =>
    (a -> g b) -> f a -> g (f b)
    forall (f :: * -> *) a b.
    Functor f =>
    (a -> Co f b) -> f a -> Co f (f b)
    collect (f (m a) -> Co f (m a)
    forall (f :: * -> *) a. f a -> Co f a
    Co (f (m a) -> Co f (m a))
    -> (ReaderT f m a -> f (m a)) -> ReaderT f m a -> Co f (m a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m a -> f (m a)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT)

    instance (Representable f, Representable m, Semigroup (Rep f), Semigroup (Rep m)) => Extend (ReaderT f m) where
      extended :: forall a b. (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b
    extended = (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b
    forall (f :: * -> *) a b.
    (Representable f, Semigroup (Rep f)) =>
    (f a -> b) -> f a -> f b
    extendedRep
      duplicated :: forall a. ReaderT f m a -> ReaderT f m (ReaderT f m a)
    duplicated = ReaderT f m a -> ReaderT f m (ReaderT f m a)
    forall (f :: * -> *) a.
    (Representable f, Semigroup (Rep f)) =>
    f a -> f (f a)
    duplicatedRep

    instance (Representable f, Representable m, Monoid (Rep f), Monoid (Rep m)) => Comonad (ReaderT f m) where
      extend :: forall a b. (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b
    extend = (ReaderT f m a -> b) -> ReaderT f m a -> ReaderT f m b
    forall (f :: * -> *) a b.
    (Representable f, Monoid (Rep f)) =>
    (f a -> b) -> f a -> f b
    extendRep
      duplicate :: forall a. ReaderT f m a -> ReaderT f m (ReaderT f m a)
    duplicate = ReaderT f m a -> ReaderT f m (ReaderT f m a)
    forall (f :: * -> *) a.
    (Representable f, Monoid (Rep f)) =>
    f a -> f (f a)
    duplicateRep
      extract :: forall a. ReaderT f m a -> a
    extract = ReaderT f m a -> a
    forall (f :: * -> *) a.
    (Representable f, Monoid (Rep f)) =>
    f a -> a
    extractRep

    instance (Representable f, MonadIO m) => MonadIO (ReaderT f m) where
      liftIO :: forall a. IO a -> ReaderT f m a
    liftIO = m a -> ReaderT f m a
    forall (m :: * -> *) a. Monad m => m a -> ReaderT f m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> ReaderT f m a) -> (IO a -> m a) -> IO a -> ReaderT f m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . IO a -> m a
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO

    instance (Representable f, MonadWriter w m) => MonadWriter w (ReaderT f m) where
      tell :: w -> ReaderT f m ()
    tell = m () -> ReaderT f m ()
    forall (m :: * -> *) a. Monad m => m a -> ReaderT f m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> ReaderT f m ()) -> (w -> m ()) -> w -> ReaderT f m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . w -> m ()
    forall w (m :: * -> *). MonadWriter w m => w -> m ()
    tell
      listen :: forall a. ReaderT f m a -> ReaderT f m (a, w)
    listen (ReaderT f (m a)
    m) = f (m (a, w)) -> ReaderT f m (a, w)
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m (a, w)) -> ReaderT f m (a, w))
    -> f (m (a, w)) -> ReaderT f m (a, w)
    forall a b. (a -> b) -> a -> b
    $ (Rep f -> m (a, w)) -> f (m (a, w))
    forall a. (Rep f -> a) -> f a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate ((Rep f -> m (a, w)) -> f (m (a, w)))
    -> (Rep f -> m (a, w)) -> f (m (a, w))
    forall a b. (a -> b) -> a -> b
    $ m a -> m (a, w)
    forall a. m a -> m (a, w)
    forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
    Writer.listen (m a -> m (a, w)) -> (Rep f -> m a) -> Rep f -> m (a, w)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . f (m a) -> Rep f -> m a
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index f (m a)
    m
      pass :: forall a. ReaderT f m (a, w -> w) -> ReaderT f m a
    pass (ReaderT f (m (a, w -> w))
    m) = f (m a) -> ReaderT f m a
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (m a) -> ReaderT f m a) -> f (m a) -> ReaderT f m a
    forall a b. (a -> b) -> a -> b
    $ (Rep f -> m a) -> f (m a)
    forall a. (Rep f -> a) -> f a
    forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
    tabulate ((Rep f -> m a) -> f (m a)) -> (Rep f -> m a) -> f (m a)
    forall a b. (a -> b) -> a -> b
    $ m (a, w -> w) -> m a
    forall a. m (a, w -> w) -> m a
    forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
    Writer.pass (m (a, w -> w) -> m a) -> (Rep f -> m (a, w -> w)) -> Rep f -> m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . f (m (a, w -> w)) -> Rep f -> m (a, w -> w)
    forall a. f a -> Rep f -> a
    forall (f :: * -> *) a. Representable f => f a -> Rep f -> a
    index f (m (a, w -> w))
    m

    -- misc. instances that can exist, but aren't particularly about representability

    instance (Foldable f, Foldable m) => Foldable (ReaderT f m) where
      foldMap :: forall m a. Monoid m => (a -> m) -> ReaderT f m a -> m
    foldMap a -> m
    f = (m a -> m) -> f (m a) -> m
    forall m a. Monoid m => (a -> m) -> f a -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap ((a -> m) -> m a -> m
    forall m a. Monoid m => (a -> m) -> m a -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap a -> m
    f) (f (m a) -> m) -> (ReaderT f m a -> f (m a)) -> ReaderT f m a -> m
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m a -> f (m a)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT

    instance (Foldable1 f, Foldable1 m) => Foldable1 (ReaderT f m) where
      foldMap1 :: forall m a. Semigroup m => (a -> m) -> ReaderT f m a -> m
    foldMap1 a -> m
    f = (m a -> m) -> f (m a) -> m
    forall m a. Semigroup m => (a -> m) -> f a -> m
    forall (t :: * -> *) m a.
    (Foldable1 t, Semigroup m) =>
    (a -> m) -> t a -> m
    foldMap1 ((a -> m) -> m a -> m
    forall m a. Semigroup m => (a -> m) -> m a -> m
    forall (t :: * -> *) m a.
    (Foldable1 t, Semigroup m) =>
    (a -> m) -> t a -> m
    foldMap1 a -> m
    f) (f (m a) -> m) -> (ReaderT f m a -> f (m a)) -> ReaderT f m a -> m
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m a -> f (m a)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT

    instance (Traversable f, Traversable m) => Traversable (ReaderT f m) where
      traverse :: forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> ReaderT f m a -> f (ReaderT f m b)
    traverse a -> f b
    f = (f (m b) -> ReaderT f m b) -> f (f (m b)) -> f (ReaderT f m b)
    forall a b. (a -> b) -> f a -> f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (f (m b)) -> f (ReaderT f m b))
    -> (ReaderT f m a -> f (f (m b)))
    -> ReaderT f m a
    -> f (ReaderT f m b)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (m a -> f (m b)) -> f (m a) -> f (f (m b))
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> f a -> f (f b)
    traverse ((a -> f b) -> m a -> f (m b)
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> m a -> f (m b)
    traverse a -> f b
    f) (f (m a) -> f (f (m b)))
    -> (ReaderT f m a -> f (m a)) -> ReaderT f m a -> f (f (m b))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m a -> f (m a)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT

    instance (Traversable1 f, Traversable1 m) => Traversable1 (ReaderT f m) where
      traverse1 :: forall (f :: * -> *) a b.
    Apply f =>
    (a -> f b) -> ReaderT f m a -> f (ReaderT f m b)
    traverse1 a -> f b
    f = (f (m b) -> ReaderT f m b) -> f (f (m b)) -> f (ReaderT f m b)
    forall a b. (a -> b) -> f a -> f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap f (m b) -> ReaderT f m b
    forall (f :: * -> *) (m :: * -> *) b. f (m b) -> ReaderT f m b
    ReaderT (f (f (m b)) -> f (ReaderT f m b))
    -> (ReaderT f m a -> f (f (m b)))
    -> ReaderT f m a
    -> f (ReaderT f m b)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (m a -> f (m b)) -> f (m a) -> f (f (m b))
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable1 t, Apply f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b. Apply f => (a -> f b) -> f a -> f (f b)
    traverse1 ((a -> f b) -> m a -> f (m b)
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable1 t, Apply f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b. Apply f => (a -> f b) -> m a -> f (m b)
    traverse1 a -> f b
    f) (f (m a) -> f (f (m b)))
    -> (ReaderT f m a -> f (m a)) -> ReaderT f m a -> f (f (m b))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT f m a -> f (m a)
    forall (f :: * -> *) (m :: * -> *) b. ReaderT f m b -> f (m b)
    getReaderT