kan-extensions-5.2.1: Kan extensions, Kan lifts, the Yoneda lemma, and (co)density (co)monads

Copyright (C) 2011-2016 Edward Kmett BSD-style (see the file LICENSE) Edward Kmett provisional MPTCs, fundeps Trustworthy Haskell2010

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 FieldsrunYoneda :: forall b. (a -> b) -> f b
Instances
 Source # Instance detailsDefined in Data.Functor.Yoneda Methodslower :: Comonad w => Yoneda w a -> w a # Source # Instance detailsDefined in Data.Functor.Yoneda Methodslift :: Monad m => m a -> Yoneda m a # (Functor f, MonadFree f m) => MonadFree f (Yoneda m) Source # Instance detailsDefined in Data.Functor.Yoneda Methodswrap :: f (Yoneda m a) -> Yoneda m a # Monad m => Monad (Yoneda m) Source # Instance detailsDefined 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 #fail :: String -> Yoneda m a # Source # Instance detailsDefined in Data.Functor.Yoneda Methodsfmap :: (a -> b) -> Yoneda f a -> Yoneda f b #(<\$) :: a -> Yoneda f b -> Yoneda f a # MonadFix m => MonadFix (Yoneda m) Source # Instance detailsDefined in Data.Functor.Yoneda Methodsmfix :: (a -> Yoneda m a) -> Yoneda m a # Applicative f => Applicative (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda Methodspure :: 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 # Foldable f => Foldable (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda Methodsfold :: 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 # Instance detailsDefined in Data.Functor.Yoneda Methodstraverse :: 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) # Source # Instance detailsDefined in Data.Functor.Yoneda Methodsdistribute :: 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) # Source # Instance detailsDefined in Data.Functor.Yoneda Associated Typestype Rep (Yoneda g) :: Type # Methodstabulate :: (Rep (Yoneda g) -> a) -> Yoneda g a #index :: Yoneda g a -> Rep (Yoneda g) -> a # Eq1 f => Eq1 (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda MethodsliftEq :: (a -> b -> Bool) -> Yoneda f a -> Yoneda f b -> Bool # Ord1 f => Ord1 (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda MethodsliftCompare :: (a -> b -> Ordering) -> Yoneda f a -> Yoneda f b -> Ordering # (Read1 f, Functor f) => Read1 (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda MethodsliftReadsPrec :: (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 detailsDefined in Data.Functor.Yoneda MethodsliftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Yoneda f a -> ShowS #liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Yoneda f a] -> ShowS # Alternative f => Alternative (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda Methodsempty :: 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 # Instance detailsDefined in Data.Functor.Yoneda Methodsmzero :: Yoneda m a #mplus :: Yoneda m a -> Yoneda m a -> Yoneda m a # Comonad w => Comonad (Yoneda w) Source # Instance detailsDefined in Data.Functor.Yoneda Methodsextract :: Yoneda w a -> a #duplicate :: Yoneda w a -> Yoneda w (Yoneda w a) #extend :: (Yoneda w a -> b) -> Yoneda w a -> Yoneda w b # Source # Instance detailsDefined in Data.Functor.Yoneda Methodstraverse1 :: Apply f0 => (a -> f0 b) -> Yoneda f a -> f0 (Yoneda f b) #sequence1 :: Apply f0 => Yoneda f (f0 b) -> f0 (Yoneda f b) # Foldable1 f => Foldable1 (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda Methodsfold1 :: Semigroup m => Yoneda f m -> m #foldMap1 :: Semigroup m => (a -> m) -> Yoneda f a -> m #toNonEmpty :: Yoneda f a -> NonEmpty a # Plus f => Plus (Yoneda f) Source # Instance detailsDefined in Data.Functor.Yoneda Methodszero :: Yoneda f a # Alt f => Alt (Yoneda f) Source # Instance detailsDefined 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 detailsDefined 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 detailsDefined 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 detailsDefined in Data.Functor.Yoneda Methodsduplicated :: Yoneda w a -> Yoneda w (Yoneda w a) #extended :: (Yoneda w a -> b) -> Yoneda w a -> Yoneda w b # Adjunction f g => Adjunction (Yoneda f) (Yoneda g) Source # Instance detailsDefined in Data.Functor.Yoneda Methodsunit :: 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 # (Eq1 f, Eq a) => Eq (Yoneda f a) Source # Instance detailsDefined 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 detailsDefined in Data.Functor.Yoneda Methodscompare :: 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 # Instance detailsDefined in Data.Functor.Yoneda MethodsreadsPrec :: 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) Source # Instance detailsDefined in Data.Functor.Yoneda MethodsshowsPrec :: Int -> Yoneda f a -> ShowS #show :: Yoneda f a -> String #showList :: [Yoneda f a] -> ShowS # type Rep (Yoneda g) Source # Instance detailsDefined 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 . 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 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 . ranToYoneda ≡ id
ranToYoneda . yonedaToRan ≡ id