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

Copyright(C) 2011-2013 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
PortabilityGADTs, MPTCs, fundeps
Safe HaskellTrustworthy
LanguageHaskell98

Data.Functor.Coyoneda

Contents

Description

The co-Yoneda lemma for a covariant Functor f states that Coyoneda f is naturally isomorphic to f.

Synopsis

Documentation

data Coyoneda f a where Source

A covariant Functor suitable for Yoneda reduction

Constructors

Coyoneda :: (b -> a) -> f b -> Coyoneda f a 

Instances

ComonadTrans Coyoneda Source 

Methods

lower :: Comonad w => Coyoneda w a -> w a

MonadTrans Coyoneda Source 

Methods

lift :: Monad m => m a -> Coyoneda m a

Monad m => Monad (Coyoneda m) Source 

Methods

(>>=) :: Coyoneda m a -> (a -> Coyoneda m b) -> Coyoneda m b

(>>) :: Coyoneda m a -> Coyoneda m b -> Coyoneda m b

return :: a -> Coyoneda m a

fail :: String -> Coyoneda m a

Functor (Coyoneda f) Source 

Methods

fmap :: (a -> b) -> Coyoneda f a -> Coyoneda f b

(<$) :: a -> Coyoneda f b -> Coyoneda f a

MonadFix f => MonadFix (Coyoneda f) Source 

Methods

mfix :: (a -> Coyoneda f a) -> Coyoneda f a

Applicative f => Applicative (Coyoneda f) Source 

Methods

pure :: a -> Coyoneda f a

(<*>) :: Coyoneda f (a -> b) -> Coyoneda f a -> Coyoneda f b

(*>) :: Coyoneda f a -> Coyoneda f b -> Coyoneda f b

(<*) :: Coyoneda f a -> Coyoneda f b -> Coyoneda f a

Foldable f => Foldable (Coyoneda f) Source 

Methods

fold :: Monoid m => Coyoneda f m -> m

foldMap :: Monoid m => (a -> m) -> Coyoneda f a -> m

foldr :: (a -> b -> b) -> b -> Coyoneda f a -> b

foldr' :: (a -> b -> b) -> b -> Coyoneda f a -> b

foldl :: (b -> a -> b) -> b -> Coyoneda f a -> b

foldl' :: (b -> a -> b) -> b -> Coyoneda f a -> b

foldr1 :: (a -> a -> a) -> Coyoneda f a -> a

foldl1 :: (a -> a -> a) -> Coyoneda f a -> a

toList :: Coyoneda f a -> [a]

null :: Coyoneda f a -> Bool

length :: Coyoneda f a -> Int

elem :: Eq a => a -> Coyoneda f a -> Bool

maximum :: Ord a => Coyoneda f a -> a

minimum :: Ord a => Coyoneda f a -> a

sum :: Num a => Coyoneda f a -> a

product :: Num a => Coyoneda f a -> a

Traversable f => Traversable (Coyoneda f) Source 

Methods

traverse :: Applicative b => (a -> b c) -> Coyoneda f a -> b (Coyoneda f c)

sequenceA :: Applicative a => Coyoneda f (a b) -> a (Coyoneda f b)

mapM :: Monad m => (a -> m b) -> Coyoneda f a -> m (Coyoneda f b)

sequence :: Monad m => Coyoneda f (m a) -> m (Coyoneda f a)

Distributive f => Distributive (Coyoneda f) Source 

Methods

distribute :: Functor a => a (Coyoneda f b) -> Coyoneda f (a b)

collect :: Functor c => (a -> Coyoneda f b) -> c a -> Coyoneda f (c b)

distributeM :: Monad m => m (Coyoneda f a) -> Coyoneda f (m a)

collectM :: Monad m => (a -> Coyoneda f b) -> m a -> Coyoneda f (m b)

Representable f => Representable (Coyoneda f) Source 

Associated Types

type Rep (Coyoneda f :: * -> *) :: *

Methods

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

index :: Coyoneda f a -> Rep (Coyoneda f) -> a

Alternative f => Alternative (Coyoneda f) Source 

Methods

empty :: Coyoneda f a

(<|>) :: Coyoneda f a -> Coyoneda f a -> Coyoneda f a

some :: Coyoneda f a -> Coyoneda f [a]

many :: Coyoneda f a -> Coyoneda f [a]

MonadPlus f => MonadPlus (Coyoneda f) Source 

Methods

mzero :: Coyoneda f a

mplus :: Coyoneda f a -> Coyoneda f a -> Coyoneda f a

Comonad w => Comonad (Coyoneda w) Source 

Methods

extract :: Coyoneda w a -> a

duplicate :: Coyoneda w a -> Coyoneda w (Coyoneda w a)

extend :: (Coyoneda w a -> b) -> Coyoneda w a -> Coyoneda w b

Plus f => Plus (Coyoneda f) Source 

Methods

zero :: Coyoneda f a

Traversable1 f => Traversable1 (Coyoneda f) Source 

Methods

traverse1 :: Apply b => (a -> b c) -> Coyoneda f a -> b (Coyoneda f c)

sequence1 :: Apply a => Coyoneda f (a b) -> a (Coyoneda f b)

Alt f => Alt (Coyoneda f) Source 

Methods

(<!>) :: Coyoneda f a -> Coyoneda f a -> Coyoneda f a

some :: Applicative (Coyoneda f) => Coyoneda f a -> Coyoneda f [a]

many :: Applicative (Coyoneda f) => Coyoneda f a -> Coyoneda f [a]

Apply f => Apply (Coyoneda f) Source 

Methods

(<.>) :: Coyoneda f (a -> b) -> Coyoneda f a -> Coyoneda f b

(.>) :: Coyoneda f a -> Coyoneda f b -> Coyoneda f b

(<.) :: Coyoneda f a -> Coyoneda f b -> Coyoneda f a

Bind m => Bind (Coyoneda m) Source 

Methods

(>>-) :: Coyoneda m a -> (a -> Coyoneda m b) -> Coyoneda m b

join :: Coyoneda m (Coyoneda m a) -> Coyoneda m a

Extend w => Extend (Coyoneda w) Source 

Methods

duplicated :: Coyoneda w a -> Coyoneda w (Coyoneda w a)

extended :: (Coyoneda w a -> b) -> Coyoneda w a -> Coyoneda w b

Foldable1 f => Foldable1 (Coyoneda f) Source 

Methods

fold1 :: Semigroup m => Coyoneda f m -> m

foldMap1 :: Semigroup m => (a -> m) -> Coyoneda f a -> m

Adjunction f g => Adjunction (Coyoneda f) (Coyoneda g) Source 

Methods

unit :: a -> Coyoneda g (Coyoneda f a)

counit :: Coyoneda f (Coyoneda g a) -> a

leftAdjunct :: (Coyoneda f a -> b) -> a -> Coyoneda g b

rightAdjunct :: (a -> Coyoneda g b) -> Coyoneda f a -> b

(Functor f, Eq (f a)) => Eq (Coyoneda f a) Source 

Methods

(==) :: Coyoneda f a -> Coyoneda f a -> Bool

(/=) :: Coyoneda f a -> Coyoneda f a -> Bool

(Functor f, Ord (f a)) => Ord (Coyoneda f a) Source 

Methods

compare :: Coyoneda f a -> Coyoneda f a -> Ordering

(<) :: Coyoneda f a -> Coyoneda f a -> Bool

(<=) :: Coyoneda f a -> Coyoneda f a -> Bool

(>) :: Coyoneda f a -> Coyoneda f a -> Bool

(>=) :: Coyoneda f a -> Coyoneda f a -> Bool

max :: Coyoneda f a -> Coyoneda f a -> Coyoneda f a

min :: Coyoneda f a -> Coyoneda f a -> Coyoneda f a

(Functor f, Read (f a)) => Read (Coyoneda f a) Source 
(Functor f, Show (f a)) => Show (Coyoneda f a) Source 

Methods

showsPrec :: Int -> Coyoneda f a -> ShowS

show :: Coyoneda f a -> String

showList :: [Coyoneda f a] -> ShowS

type Rep (Coyoneda f) = Rep f Source 

liftCoyoneda :: f a -> Coyoneda f a Source

Yoneda "expansion"

liftCoyoneda . lowerCoyonedaid
lowerCoyoneda . liftCoyonedaid
lowerCoyoneda (liftCoyoneda fa) = -- by definition
lowerCoyoneda (Coyoneda id fa)  = -- by definition
fmap id fa                      = -- functor law
fa
lift = liftCoyoneda

lowerCoyoneda :: Functor f => Coyoneda f a -> f a Source

Yoneda reduction lets us walk under the existential and apply fmap.

Mnemonically, "Yoneda reduction" sounds like and works a bit like β-reduction.

http://ncatlab.org/nlab/show/Yoneda+reduction

You can view Coyoneda as just the arguments to fmap tupled up.

lower = lowerM = lowerCoyoneda

lowerM :: Monad f => Coyoneda f a -> f a Source

Yoneda reduction given a Monad lets us walk under the existential and apply liftM.

You can view Coyoneda as just the arguments to liftM tupled up.

lower = lowerM = lowerCoyoneda

as a Left Kan extension

coyonedaToLan :: Coyoneda f a -> Lan Identity f a Source

Coyoneda f is the left Kan extension of f along the Identity functor.

coyonedaToLan . lanToCoyonedaid
lanToCoyoneda . coyonedaToLanid

as a Left Kan lift

coyonedaToLift :: Coyoneda f a -> Lift Identity f a Source

Coyoneda f is the left Kan lift of f along the Identity functor.

coyonedaToLift . liftToCoyonedaid
liftToCoyoneda . coyonedaToLiftid