kan-extensions-5.0.2: 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 # |
Methods lower :: Comonad w => Yoneda w a -> w a #
MonadTrans Yoneda # |
Methods lift :: Monad m => m a -> Yoneda m a #
(Functor f, MonadFree f m) => MonadFree f (Yoneda m) # |
Methods wrap :: f (Yoneda m a) -> Yoneda m a #
Monad m => Monad (Yoneda m) # |
Methods (>>=) :: Yoneda m a -> (a -> Yoneda m b) -> Yoneda m b # (>>) :: Yoneda m a -> Yoneda m b -> Yoneda m b # return :: a -> Yoneda m a # fail :: String -> Yoneda m a #
Functor (Yoneda f) # |
Methods fmap :: (a -> b) -> Yoneda f a -> Yoneda f b # (<$) :: a -> Yoneda f b -> Yoneda f a #
MonadFix m => MonadFix (Yoneda m) # |
Methods mfix :: (a -> Yoneda m a) -> Yoneda m a #
Applicative f => Applicative (Yoneda f) # |
Methods pure :: a -> Yoneda f a # (<*>) :: Yoneda f (a -> b) -> Yoneda f a -> Yoneda f b # (*>) :: Yoneda f a -> Yoneda f b -> Yoneda f b # (<*) :: Yoneda f a -> Yoneda f b -> Yoneda f a #
Foldable f => Foldable (Yoneda f) # |
Methods fold :: Monoid m => Yoneda f m -> m # foldMap :: Monoid m => (a -> m) -> Yoneda f a -> m # foldr :: (a -> b -> b) -> b -> Yoneda f a -> b # foldr' :: (a -> b -> b) -> b -> Yoneda f a -> b # foldl :: (b -> a -> b) -> b -> Yoneda f a -> b # foldl' :: (b -> a -> b) -> b -> Yoneda f a -> b # foldr1 :: (a -> a -> a) -> Yoneda f a -> a # foldl1 :: (a -> a -> a) -> Yoneda f a -> a # toList :: Yoneda f a -> [a] # null :: Yoneda f a -> Bool # length :: Yoneda f a -> Int # elem :: Eq a => a -> Yoneda f a -> Bool # maximum :: Ord a => Yoneda f a -> a # minimum :: Ord a => Yoneda f a -> a # sum :: Num a => Yoneda f a -> a # product :: Num a => Yoneda f a -> a #
Traversable f => Traversable (Yoneda f) # |
Methods traverse :: Applicative f => (a -> f b) -> Yoneda f a -> f (Yoneda f b) # sequenceA :: Applicative f => Yoneda f (f a) -> f (Yoneda f a) # mapM :: Monad m => (a -> m b) -> Yoneda f a -> m (Yoneda f b) # sequence :: Monad m => Yoneda f (m a) -> m (Yoneda f a) #
Distributive f => Distributive (Yoneda f) # |
Methods distribute :: Functor f => f (Yoneda f a) -> Yoneda f (f a) # collect :: Functor f => (a -> Yoneda f b) -> f a -> Yoneda f (f b) # distributeM :: Monad m => m (Yoneda f a) -> Yoneda f (m a) # collectM :: Monad m => (a -> Yoneda f b) -> m a -> Yoneda f (m b) #
Representable g => Representable (Yoneda g) # |
Associated Types type Rep (Yoneda g :: * -> *) :: * # Methods tabulate :: (Rep (Yoneda g) -> a) -> Yoneda g a # index :: Yoneda g a -> Rep (Yoneda g) -> a #
Alternative f => Alternative (Yoneda f) # |
Methods empty :: Yoneda f a # (<|>) :: Yoneda f a -> Yoneda f a -> Yoneda f a # some :: Yoneda f a -> Yoneda f [a] # many :: Yoneda f a -> Yoneda f [a] #
MonadPlus m => MonadPlus (Yoneda m) # |
Methods mzero :: Yoneda m a # mplus :: Yoneda m a -> Yoneda m a -> Yoneda m a #
Comonad w => Comonad (Yoneda w) # |
Methods extract :: Yoneda w a -> a # duplicate :: Yoneda w a -> Yoneda w (Yoneda w a) # extend :: (Yoneda w a -> b) -> Yoneda w a -> Yoneda w b #
Traversable1 f => Traversable1 (Yoneda f) # |
Methods traverse1 :: Apply f => (a -> f b) -> Yoneda f a -> f (Yoneda f b) # sequence1 :: Apply f => Yoneda f (f b) -> f (Yoneda f b) #
Plus f => Plus (Yoneda f) # |
Methods zero :: Yoneda f a #
Alt f => Alt (Yoneda f) # |
Methods (<!>) :: Yoneda f a -> Yoneda f a -> Yoneda f a # some :: Applicative (Yoneda f) => Yoneda f a -> Yoneda f [a] # many :: Applicative (Yoneda f) => Yoneda f a -> Yoneda f [a] #
Apply f => Apply (Yoneda f) # |
Methods (<.>) :: Yoneda f (a -> b) -> Yoneda f a -> Yoneda f b # (.>) :: Yoneda f a -> Yoneda f b -> Yoneda f b # (<.) :: Yoneda f a -> Yoneda f b -> Yoneda f a #
Bind m => Bind (Yoneda m) # |
Methods (>>-) :: Yoneda m a -> (a -> Yoneda m b) -> Yoneda m b # join :: Yoneda m (Yoneda m a) -> Yoneda m a #
Extend w => Extend (Yoneda w) # |
Methods duplicated :: Yoneda w a -> Yoneda w (Yoneda w a) # extended :: (Yoneda w a -> b) -> Yoneda w a -> Yoneda w b #
Foldable1 f => Foldable1 (Yoneda f) # |
Methods fold1 :: Semigroup m => Yoneda f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Yoneda f a -> m # toNonEmpty :: Yoneda f a -> NonEmpty a #
Adjunction f g => Adjunction (Yoneda f) (Yoneda g) # |
Methods unit :: a -> Yoneda g (Yoneda f a) # counit :: Yoneda f (Yoneda g a) -> a # leftAdjunct :: (Yoneda f a -> b) -> a -> Yoneda g b # rightAdjunct :: (a -> Yoneda g b) -> Yoneda f a -> b #
Eq (f a) => Eq (Yoneda f a) # |
Methods (==) :: Yoneda f a -> Yoneda f a -> Bool # (/=) :: Yoneda f a -> Yoneda f a -> Bool #
Ord (f a) => Ord (Yoneda f a) # |
Methods compare :: Yoneda f a -> Yoneda f a -> Ordering # (<) :: Yoneda f a -> Yoneda f a -> Bool # (<=) :: Yoneda f a -> Yoneda f a -> Bool # (>) :: Yoneda f a -> Yoneda f a -> Bool # (>=) :: Yoneda f a -> Yoneda f a -> Bool # max :: Yoneda f a -> Yoneda f a -> Yoneda f a # min :: Yoneda f a -> Yoneda f a -> Yoneda f a #
(Functor f, Read (f a)) => Read (Yoneda f a) # |
Methods readsPrec :: Int -> ReadS (Yoneda f a) # readList :: ReadS [Yoneda f a] # readPrec :: ReadPrec (Yoneda f a) # readListPrec :: ReadPrec [Yoneda f a] #
Show (f a) => Show (Yoneda f a) # |
Methods showsPrec :: Int -> Yoneda f a -> ShowS # show :: Yoneda f a -> String # showList :: [Yoneda f a] -> ShowS #
type Rep (Yoneda g) # |
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 #