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
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
PortabilityMPTCs, fundeps
Safe HaskellTrustworthy
LanguageHaskell98

Data.Functor.Yoneda

Contents

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

Documentation

newtype Yoneda f a Source #

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

Constructors

Yoneda 

Fields

Instances

ComonadTrans Yoneda Source # 

Methods

lower :: Comonad w => Yoneda w a -> w a #

MonadTrans Yoneda Source # 

Methods

lift :: Monad m => m a -> Yoneda m a #

(Functor f, MonadFree f m) => MonadFree f (Yoneda m) Source # 

Methods

wrap :: f (Yoneda m a) -> Yoneda m a #

Monad m => Monad (Yoneda m) Source # 

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) Source # 

Methods

fmap :: (a -> b) -> Yoneda f a -> Yoneda f b #

(<$) :: a -> Yoneda f b -> Yoneda f a #

MonadFix m => MonadFix (Yoneda m) Source # 

Methods

mfix :: (a -> Yoneda m a) -> Yoneda m a #

Applicative f => Applicative (Yoneda f) Source # 

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) Source # 

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) Source # 

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) Source # 

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) Source # 

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) Source # 

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) Source # 

Methods

mzero :: Yoneda m a #

mplus :: Yoneda m a -> Yoneda m a -> Yoneda m a #

Comonad w => Comonad (Yoneda w) Source # 

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) Source # 

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) Source # 

Methods

zero :: Yoneda f a #

Alt f => Alt (Yoneda f) Source # 

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) Source # 

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) Source # 

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) Source # 

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) Source # 

Methods

fold1 :: Semigroup m => Yoneda f m -> m #

foldMap1 :: Semigroup m => (a -> m) -> Yoneda f a -> m #

Adjunction f g => Adjunction (Yoneda f) (Yoneda g) Source # 

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) Source # 

Methods

(==) :: Yoneda f a -> Yoneda f a -> Bool #

(/=) :: Yoneda f a -> Yoneda f a -> Bool #

Ord (f a) => Ord (Yoneda f a) Source # 

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) Source # 
Show (f a) => Show (Yoneda f a) Source # 

Methods

showsPrec :: Int -> Yoneda f a -> ShowS #

show :: Yoneda f a -> String #

showList :: [Yoneda f a] -> ShowS #

type Rep (Yoneda g) Source # 
type Rep (Yoneda g) = Rep g

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

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

liftYoneda . lowerYonedaid
lowerYoneda . liftYonedaid
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 Source #

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

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

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

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

as a right Kan extension

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

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

yonedaToRan . ranToYonedaid
ranToYoneda . yonedaToRanid