kan-extensions-5.2.6: Kan extensions, Kan lifts, 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
LanguageHaskell2010

Data.Functor.Yoneda

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 :: Type -> Type) a Source #

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

Constructors

Yoneda 

Fields

Instances

Instances details
ComonadTrans Yoneda Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

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

MonadTrans Yoneda Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

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

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

Defined in Data.Functor.Yoneda

Methods

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

Representable g => Representable (Yoneda g) Source # 
Instance details

Defined in Data.Functor.Yoneda

Associated Types

type Rep (Yoneda g) 
Instance details

Defined in Data.Functor.Yoneda

type Rep (Yoneda g) = Rep g

Methods

tabulate :: (Rep (Yoneda g) -> a) -> Yoneda g a #

index :: Yoneda g a -> Rep (Yoneda g) -> a #

MonadFix m => MonadFix (Yoneda m) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

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

Foldable f => Foldable (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

fold :: Monoid m => Yoneda f m -> m #

foldMap :: Monoid m => (a -> m) -> Yoneda f a -> 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 #

Foldable1 f => Foldable1 (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

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

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

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

toNonEmpty :: Yoneda f a -> NonEmpty a #

maximum :: Ord a => Yoneda f a -> a #

minimum :: Ord a => Yoneda f a -> a #

head :: Yoneda f a -> a #

last :: Yoneda f a -> a #

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

foldlMap1' :: (a -> b) -> (b -> a -> b) -> Yoneda f a -> b #

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

foldrMap1' :: (a -> b) -> (a -> b -> b) -> Yoneda f a -> b #

Eq1 f => Eq1 (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

liftEq :: (a -> b -> Bool) -> Yoneda f a -> Yoneda f b -> Bool #

Ord1 f => Ord1 (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

liftCompare :: (a -> b -> Ordering) -> Yoneda f a -> Yoneda f b -> Ordering #

(Read1 f, Functor f) => Read1 (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Yoneda f a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Yoneda f a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Yoneda f a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Yoneda f a] #

Show1 f => Show1 (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Yoneda f a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Yoneda f a] -> ShowS #

Traversable f => Traversable (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

traverse :: Applicative f0 => (a -> f0 b) -> Yoneda f a -> f0 (Yoneda f b) #

sequenceA :: Applicative f0 => Yoneda f (f0 a) -> f0 (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) #

Alternative f => Alternative (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

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] #

Applicative f => Applicative (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

pure :: a -> Yoneda f a #

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

liftA2 :: (a -> b -> c) -> Yoneda f a -> Yoneda f b -> Yoneda f c #

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

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

Functor (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

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

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

Monad m => Monad (Yoneda m) Source # 
Instance details

Defined in Data.Functor.Yoneda

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 #

MonadPlus m => MonadPlus (Yoneda m) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

mzero :: Yoneda m a #

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

Comonad w => Comonad (Yoneda w) Source # 
Instance details

Defined in Data.Functor.Yoneda

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 #

Distributive f => Distributive (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

distribute :: Functor f0 => f0 (Yoneda f a) -> Yoneda f (f0 a) #

collect :: Functor f0 => (a -> Yoneda f b) -> f0 a -> Yoneda f (f0 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) #

Alt f => Alt (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

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 # 
Instance details

Defined in Data.Functor.Yoneda

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 #

liftF2 :: (a -> b -> c) -> Yoneda f a -> Yoneda f b -> Yoneda f c #

Bind m => Bind (Yoneda m) Source # 
Instance details

Defined in Data.Functor.Yoneda

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 # 
Instance details

Defined in Data.Functor.Yoneda

Methods

duplicated :: Yoneda w a -> Yoneda w (Yoneda w a) #

extended :: (Yoneda w a -> b) -> Yoneda w a -> Yoneda w b #

Plus f => Plus (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

zero :: Yoneda f a #

Traversable1 f => Traversable1 (Yoneda f) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

traverse1 :: Apply f0 => (a -> f0 b) -> Yoneda f a -> f0 (Yoneda f b) #

sequence1 :: Apply f0 => Yoneda f (f0 b) -> f0 (Yoneda f b) #

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

Defined in Data.Functor.Yoneda

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 #

(Functor f, Read (f a)) => Read (Yoneda f a) Source # 
Instance details

Defined in Data.Functor.Yoneda

Show (f a) => Show (Yoneda f a) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

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

show :: Yoneda f a -> String #

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

(Eq1 f, Eq a) => Eq (Yoneda f a) Source # 
Instance details

Defined in Data.Functor.Yoneda

Methods

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

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

(Ord1 f, Ord a) => Ord (Yoneda f a) Source # 
Instance details

Defined in Data.Functor.Yoneda

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 #

type Rep (Yoneda g) Source # 
Instance details

Defined in Data.Functor.Yoneda

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 :: forall (f :: Type -> Type) a. (Functor f, Ord (f a)) => Yoneda f a -> Yoneda f a -> Yoneda f a Source #

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

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

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

as a right Kan extension

yonedaToRan :: forall (f :: Type -> Type) a. 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

ranToYoneda :: forall (f :: Type -> Type) a. Ran Identity f a -> Yoneda f a Source #