Data.Functor.Yoneda

kan-extensions-5.0.1: Kan extensions, Kan lifts, various forms of the Yoneda lemma, and (co)density (co)monads

Copyright | (C) 2011-2016 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | MPTCs, fundeps
Safe Haskell | Trustworthy
Language | Haskell98

Data.Functor.Yoneda

Contents

- as a right Kan extension

Description

The covariant form of the Yoneda lemma states that `f` is naturally isomorphic to `Yoneda f`.

This is described in a rather intuitive fashion by Dan Piponi in

http://blog.sigfpe.com/2006/11/yoneda-lemma.html

Synopsis

- newtype Yoneda f a = Yoneda {
  - runYoneda :: forall b. (a -> b) -> f b
  }
- liftYoneda :: Functor f => f a -> Yoneda f a
- lowerYoneda :: Yoneda f a -> f a
- maxF :: (Functor f, Ord (f a)) => Yoneda f a -> Yoneda f a -> Yoneda f a
- minF :: (Functor f, Ord (f a)) => Yoneda f a -> Yoneda f a -> Yoneda f a
- maxM :: (Monad m, Ord (m a)) => Yoneda m a -> Yoneda m a -> Yoneda m a
- minM :: (Monad m, Ord (m a)) => Yoneda m a -> Yoneda m a -> Yoneda m a
- yonedaToRan :: Yoneda f a -> Ran Identity f a
- ranToYoneda :: Ran Identity f a -> Yoneda f a

# Documentation

newtype Yoneda f a

`Yoneda f a` can be viewed as the partial application of `fmap` to its second argument.

Constructors

Yoneda |
Fields runYoneda :: forall b. (a -> b) -> f b

Instances

ComonadTrans Yoneda |
MonadTrans Yoneda |
(Functor f, MonadFree f m) => MonadFree f (Yoneda m) |
Monad m => Monad (Yoneda m) |
Functor (Yoneda f) |
MonadFix m => MonadFix (Yoneda m) |
Applicative f => Applicative (Yoneda f) |
Foldable f => Foldable (Yoneda f) |
Traversable f => Traversable (Yoneda f) |
Distributive f => Distributive (Yoneda f) |
Representable g => Representable (Yoneda g) |
Alternative f => Alternative (Yoneda f) |
MonadPlus m => MonadPlus (Yoneda m) |
Comonad w => Comonad (Yoneda w) |
Plus f => Plus (Yoneda f) |
Traversable1 f => Traversable1 (Yoneda f) |
Alt f => Alt (Yoneda f) |
Apply f => Apply (Yoneda f) |
Bind m => Bind (Yoneda m) |
Extend w => Extend (Yoneda w) |
Foldable1 f => Foldable1 (Yoneda f) |
Adjunction f g => Adjunction (Yoneda f) (Yoneda g) |
Eq (f a) => Eq (Yoneda f a) |
Ord (f a) => Ord (Yoneda f a) |
(Functor f, Read (f a)) => Read (Yoneda f a) |
Show (f a) => Show (Yoneda f a) |
type Rep (Yoneda g) = Rep g |

liftYoneda :: Functor f => f a -> Yoneda f a

The natural isomorphism between `f` and ``Yoneda` f` given by the Yoneda lemma is witnessed by `liftYoneda` and `lowerYoneda`

    liftYoneda . lowerYoneda ≡ id
    lowerYoneda . liftYoneda ≡ id

    lowerYoneda (liftYoneda fa) =         -- definition
    lowerYoneda (Yoneda (f -> fmap f a)) -- definition
    (f -> fmap f fa) id                  -- beta reduction
    fmap id fa                            -- functor law
    fa

    lift = liftYoneda

lowerYoneda :: Yoneda f a -> f a

maxF :: (Functor f, Ord (f a)) => Yoneda f a -> Yoneda f a -> Yoneda f a

minF :: (Functor f, Ord (f a)) => Yoneda f a -> Yoneda f a -> Yoneda f a

maxM :: (Monad m, Ord (m a)) => Yoneda m a -> Yoneda m a -> Yoneda m a

minM :: (Monad m, Ord (m a)) => Yoneda m a -> Yoneda m a -> Yoneda m a

# as a right Kan extension

yonedaToRan :: Yoneda f a -> Ran Identity f a

`Yoneda f` can be viewed as the right Kan extension of `f` along the `Identity` functor.

    yonedaToRan . ranToYoneda ≡ id
    ranToYoneda . yonedaToRan ≡ id

ranToYoneda :: Ran Identity f a -> Yoneda f a