Data.Functor.Rep

adjunctions-4.3: Adjunctions and representable functors

Copyright | (c) Edward Kmett 2011-2014
License | BSD3
Maintainer | ekmett@gmail.com
Stability | experimental
Safe Haskell | None
Language | Haskell98

Data.Functor.Rep

Contents

- Representable Functors
- Wrapped representable functors
- Default definitions
  - Functor
  - Distributive
  - Apply/Applicative
  - Bind/Monad
  - MonadFix
  - MonadZip
  - MonadReader
  - Extend
  - Comonad
  - Comonad, with user-specified monoid

Description

Representable endofunctors over the category of Haskell types are isomorphic to the reader monad and so inherit a very large number of properties for free.

Synopsis

- class Distributive f => Representable f where
  - type Rep f :: *
- tabulated :: (Representable f, Representable g, Profunctor p, Functor h) => p (f a) (h (g b)) -> p (Rep f -> a) (h (Rep g -> b))
- newtype Co f a = Co {
  - unCo :: f a
  }
- fmapRep :: Representable f => (a -> b) -> f a -> f b
- distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a)
- apRep :: Representable f => f (a -> b) -> f a -> f b
- pureRep :: Representable f => a -> f a
- liftR2 :: Representable f => (a -> b -> c) -> f a -> f b -> f c
- liftR3 :: Representable f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- bindRep :: Representable f => f a -> (a -> f b) -> f b
- mfixRep :: Representable f => (a -> f a) -> f a
- mzipRep :: Representable f => f a -> f b -> f (a, b)
- mzipWithRep :: Representable f => (a -> b -> c) -> f a -> f b -> f c
- askRep :: Representable f => f (Rep f)
- localRep :: Representable f => (Rep f -> Rep f) -> f a -> f a
- duplicatedRep :: (Representable f, Semigroup (Rep f)) => f a -> f (f a)
- extendedRep :: (Representable f, Semigroup (Rep f)) => (f a -> b) -> f a -> f b
- duplicateRep :: (Representable f, Monoid (Rep f)) => f a -> f (f a)
- extendRep :: (Representable f, Monoid (Rep f)) => (f a -> b) -> f a -> f b
- extractRep :: (Representable f, Monoid (Rep f)) => f a -> a
- duplicateRepBy :: Representable f => (Rep f -> Rep f -> Rep f) -> f a -> f (f a)
- extendRepBy :: Representable f => (Rep f -> Rep f -> Rep f) -> (f a -> b) -> f a -> f b
- extractRepBy :: Representable f => Rep f -> f a -> a

# Representable Functors

class Distributive f => Representable f where #

A `Functor` `f` is `Representable` if `tabulate` and `index` witness an isomorphism to `(->) x`.

Every `Distributive` `Functor` is actually `Representable`.

Every `Representable` `Functor` from Hask to Hask is a right adjoint.

    tabulate . index  ≡ id
    index . tabulate  ≡ id
    tabulate . return ≡ return

Minimal complete definition

tabulate, index

Associated Types

type Rep f :: * #

Methods

tabulate :: (Rep f -> a) -> f a #

    fmap f . tabulate ≡ tabulate . fmap f

index :: f a -> Rep f -> a #

Instances

Representable Identity # |
Associated Types type Rep (Identity :: * -> *) :: * # Methods tabulate :: (Rep Identity -> a) -> Identity a # index :: Identity a -> Rep Identity -> a #
Representable Complex # |
Associated Types type Rep (Complex :: * -> *) :: * # Methods tabulate :: (Rep Complex -> a) -> Complex a # index :: Complex a -> Rep Complex -> a #
Representable Dual # |
Associated Types type Rep (Dual :: * -> *) :: * # Methods tabulate :: (Rep Dual -> a) -> Dual a # index :: Dual a -> Rep Dual -> a #
Representable Sum # |
Associated Types type Rep (Sum :: * -> *) :: * # Methods tabulate :: (Rep Sum -> a) -> Sum a # index :: Sum a -> Rep Sum -> a #
Representable Product # |
Associated Types type Rep (Product :: * -> *) :: * # Methods tabulate :: (Rep Product -> a) -> Product a # index :: Product a -> Rep Product -> a #
Representable ((->) e) # |
Associated Types type Rep ((->) e :: * -> *) :: * # Methods tabulate :: (Rep ((->) e) -> a) -> e -> a # index :: (e -> a) -> Rep ((->) e) -> a #
Representable (Proxy *) # |
Associated Types type Rep (Proxy * :: * -> *) :: * # Methods tabulate :: (Rep (Proxy *) -> a) -> Proxy * a # index :: Proxy * a -> Rep (Proxy *) -> a #
Representable f => Representable (Cofree f) # |
Associated Types type Rep (Cofree f :: * -> *) :: * # Methods tabulate :: (Rep (Cofree f) -> a) -> Cofree f a # index :: Cofree f a -> Rep (Cofree f) -> a #
Representable f => Representable (Co f) # |
Associated Types type Rep (Co f :: * -> *) :: * # Methods tabulate :: (Rep (Co f) -> a) -> Co f a # index :: Co f a -> Rep (Co f) -> a #
Representable w => Representable (TracedT s w) # |
Associated Types type Rep (TracedT s w :: * -> *) :: * # Methods tabulate :: (Rep (TracedT s w) -> a) -> TracedT s w a # index :: TracedT s w a -> Rep (TracedT s w) -> a #
Representable m => Representable (IdentityT * m) # |
Associated Types type Rep (IdentityT * m :: * -> *) :: * # Methods tabulate :: (Rep (IdentityT * m) -> a) -> IdentityT * m a # index :: IdentityT * m a -> Rep (IdentityT * m) -> a #
Representable (Tagged * t) # |
Associated Types type Rep (Tagged * t :: * -> *) :: * # Methods tabulate :: (Rep (Tagged * t) -> a) -> Tagged * t a # index :: Tagged * t a -> Rep (Tagged * t) -> a #
(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 #
(Representable f, Representable g) => Representable (Product * f g) # |
Associated Types type Rep (Product * f g :: * -> *) :: * # Methods tabulate :: (Rep (Product * f g) -> a) -> Product * f g a # index :: Product * f g a -> Rep (Product * f g) -> a #
Representable m => Representable (ReaderT * e m) # |
Associated Types type Rep (ReaderT * e m :: * -> *) :: * # Methods tabulate :: (Rep (ReaderT * e m) -> a) -> ReaderT * e m a # index :: ReaderT * e m a -> Rep (ReaderT * e m) -> a #
(Representable f, Representable g) => Representable (Compose * * f g) # |
Associated Types type Rep (Compose * * f g :: * -> *) :: * # Methods tabulate :: (Rep (Compose * * f g) -> a) -> Compose * * f g a # index :: Compose * * f g a -> Rep (Compose * * f g) -> a #

tabulated :: (Representable f, Representable g, Profunctor p, Functor h) => p (f a) (h (g b)) -> p (Rep f -> a) (h (Rep g -> b)) #

`tabulate` and `index` form two halves of an isomorphism.

This can be used with the combinators from the `lens` package.

    tabulated :: Representable f => Iso' (Rep f -> a) (f a)

# Wrapped representable functors

newtype Co f a #

Constructors

Co |
Fields unCo :: f a

Instances

ComonadTrans Co # |
Methods lower :: Comonad w => Co w a -> w a #
(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 #
Representable f => Monad (Co f) # |
Methods (>>=) :: Co f a -> (a -> Co f b) -> Co f b # (>>) :: Co f a -> Co f b -> Co f b # return :: a -> Co f a # fail :: String -> Co f a #
Functor f => Functor (Co f) # |
Methods fmap :: (a -> b) -> Co f a -> Co f b # (<$) :: a -> Co f b -> Co f a #
Representable f => Applicative (Co f) # |
Methods pure :: a -> Co f a # (<*>) :: Co f (a -> b) -> Co f a -> Co f b # (*>) :: Co f a -> Co f b -> Co f b # (<*) :: Co f a -> Co f b -> Co f a #
(Representable f, Monoid (Rep f)) => Comonad (Co f) # |
Methods extract :: Co f a -> a # duplicate :: Co f a -> Co f (Co f a) # extend :: (Co f a -> b) -> Co f a -> Co f b #
Representable f => Distributive (Co f) # |
Methods distribute :: Functor f => f (Co f a) -> Co f (f a) # collect :: Functor f => (a -> Co f b) -> f a -> Co f (f b) # distributeM :: Monad m => m (Co f a) -> Co f (m a) # collectM :: Monad m => (a -> Co f b) -> m a -> Co f (m b) #
Representable f => Apply (Co f) # |
Methods (<.>) :: Co f (a -> b) -> Co f a -> Co f b # (.>) :: Co f a -> Co f b -> Co f b # (<.) :: Co f a -> Co f b -> Co f a #
Representable f => Bind (Co f) # |
Methods (>>-) :: Co f a -> (a -> Co f b) -> Co f b # join :: Co f (Co f a) -> Co f a #
(Representable f, Semigroup (Rep f)) => Extend (Co f) # |
Methods duplicated :: Co f a -> Co f (Co f a) # extended :: (Co f a -> b) -> Co f a -> Co f b #
Representable f => Representable (Co f) # |
Associated Types type Rep (Co f :: * -> *) :: * # Methods tabulate :: (Rep (Co f) -> a) -> Co f a # index :: Co f a -> Rep (Co f) -> a #
type Rep (Co f) # |
type Rep (Co f) = Rep f

# Default definitions

## Functor

fmapRep :: Representable f => (a -> b) -> f a -> f b #

## Distributive

distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a) #

## Apply/Applicative

apRep :: Representable f => f (a -> b) -> f a -> f b #

pureRep :: Representable f => a -> f a #

liftR2 :: Representable f => (a -> b -> c) -> f a -> f b -> f c #

liftR3 :: Representable f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #

## Bind/Monad

bindRep :: Representable f => f a -> (a -> f b) -> f b #

## MonadFix

mfixRep :: Representable f => (a -> f a) -> f a #

## MonadZip

mzipRep :: Representable f => f a -> f b -> f (a, b) #

mzipWithRep :: Representable f => (a -> b -> c) -> f a -> f b -> f c #

## MonadReader

askRep :: Representable f => f (Rep f) #

localRep :: Representable f => (Rep f -> Rep f) -> f a -> f a #

## Extend

duplicatedRep :: (Representable f, Semigroup (Rep f)) => f a -> f (f a) #

extendedRep :: (Representable f, Semigroup (Rep f)) => (f a -> b) -> f a -> f b #

## Comonad

duplicateRep :: (Representable f, Monoid (Rep f)) => f a -> f (f a) #

extendRep :: (Representable f, Monoid (Rep f)) => (f a -> b) -> f a -> f b #

extractRep :: (Representable f, Monoid (Rep f)) => f a -> a #

## Comonad, with user-specified monoid

duplicateRepBy :: Representable f => (Rep f -> Rep f -> Rep f) -> f a -> f (f a) #

extendRepBy :: Representable f => (Rep f -> Rep f -> Rep f) -> (f a -> b) -> f a -> f b #

extractRepBy :: Representable f => Rep f -> f a -> a #