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.Contravariant.Rep

Contents

- Representable Contravariant Functors
- Default definitions

Description

Representable contravariant endofunctors over the category of Haskell types are isomorphic to `(_ -> r)` and resemble mappings to a fixed range.

Synopsis

- class Contravariant f => Representable f where
  - type Rep f :: *
- tabulated :: (Representable f, Representable g, Profunctor p, Functor h) => p (f a) (h (g b)) -> p (a -> Rep f) (h (b -> Rep g))
- contramapRep :: Representable f => (a -> b) -> f b -> f a

# Representable Contravariant Functors

class Contravariant f => Representable f where #

A `Contravariant` functor `f` is `Representable` if `tabulate` and `index` witness an isomorphism to `(_ -> Rep f)`.

    tabulate . index ≡ id
    index . tabulate ≡ id

Minimal complete definition

tabulate, index

Associated Types

type Rep f :: * #

Methods

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

    contramap f (tabulate g) = tabulate (g . f)

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

contramapWithRep :: (b -> Either a (Rep f)) -> f a -> f b #

    contramapWithRep f p ≡ tabulate $ either (index p) id . f

Instances

Representable Predicate # |
Associated Types type Rep (Predicate :: * -> *) :: * # Methods tabulate :: (a -> Rep Predicate) -> Predicate a # index :: Predicate a -> a -> Rep Predicate # contramapWithRep :: (b -> Either a (Rep Predicate)) -> Predicate a -> Predicate b #
Representable (Proxy *) # |
Associated Types type Rep (Proxy * :: * -> *) :: * # Methods tabulate :: (a -> Rep (Proxy *)) -> Proxy * a # index :: Proxy * a -> a -> Rep (Proxy *) # contramapWithRep :: (b -> Either a (Rep (Proxy *))) -> Proxy * a -> Proxy * b #
Representable (Op r) # |
Associated Types type Rep (Op r :: * -> *) :: * # Methods tabulate :: (a -> Rep (Op r)) -> Op r a # index :: Op r a -> a -> Rep (Op r) # contramapWithRep :: (b -> Either a (Rep (Op r))) -> Op r a -> Op r b #
(Representable f, Representable g) => Representable (Product * f g) # |
Associated Types type Rep (Product * f g :: * -> *) :: * # Methods tabulate :: (a -> Rep (Product * f g)) -> Product * f g a # index :: Product * f g a -> a -> Rep (Product * f g) # contramapWithRep :: (b -> Either a (Rep (Product * f g))) -> Product * f g a -> Product * f g b #

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

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

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

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

# Default definitions

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