Copyright | (C) 2011-2016 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | provisional |
Portability | GADTs, MPTCs, fundeps |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Data.Functor.Coyoneda
Contents
Description
Synopsis
- data Coyoneda (f :: Type -> Type) a where
- liftCoyoneda :: f a -> Coyoneda f a
- lowerCoyoneda :: Functor f => Coyoneda f a -> f a
- lowerM :: Monad f => Coyoneda f a -> f a
- hoistCoyoneda :: (forall a. f a -> g a) -> Coyoneda f b -> Coyoneda g b
- coyonedaToLan :: forall (f :: Type -> Type) a. Coyoneda f a -> Lan Identity f a
- lanToCoyoneda :: forall (f :: Type -> Type) a. Lan Identity f a -> Coyoneda f a
Documentation
data Coyoneda (f :: Type -> Type) a where Source #
A covariant Functor
suitable for Yoneda reduction
Instances
ComonadTrans Coyoneda Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
MonadTrans Coyoneda Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Representable f => Representable (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda Associated Types
| |||||
MonadFix f => MonadFix (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Foldable f => Foldable (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda Methods fold :: Monoid m => Coyoneda f m -> m foldMap :: Monoid m => (a -> m) -> Coyoneda f a -> 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 elem :: Eq a => a -> Coyoneda f a -> Bool maximum :: Ord a => Coyoneda f a -> a minimum :: Ord a => Coyoneda f a -> a | |||||
Foldable1 f => Foldable1 (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda Methods fold1 :: Semigroup m => Coyoneda f m -> m foldMap1 :: Semigroup m => (a -> m) -> Coyoneda f a -> m foldMap1' :: Semigroup m => (a -> m) -> Coyoneda f a -> m toNonEmpty :: Coyoneda f a -> NonEmpty a maximum :: Ord a => Coyoneda f a -> a minimum :: Ord a => Coyoneda f a -> a foldrMap1 :: (a -> b) -> (a -> b -> b) -> Coyoneda f a -> b foldlMap1' :: (a -> b) -> (b -> a -> b) -> Coyoneda f a -> b foldlMap1 :: (a -> b) -> (b -> a -> b) -> Coyoneda f a -> b foldrMap1' :: (a -> b) -> (a -> b -> b) -> Coyoneda f a -> b | |||||
Eq1 f => Eq1 (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Ord1 f => Ord1 (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda Methods liftCompare :: (a -> b -> Ordering) -> Coyoneda f a -> Coyoneda f b -> Ordering | |||||
Read1 f => Read1 (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Coyoneda f a) liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Coyoneda f a] liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Coyoneda f a) liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Coyoneda f a] | |||||
(Functor f, Show1 f) => Show1 (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Coyoneda f a -> ShowS liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Coyoneda f a] -> ShowS | |||||
Traversable f => Traversable (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Alternative f => Alternative (Coyoneda f) Source # | |||||
Applicative f => Applicative (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Functor (Coyoneda f) Source # | |||||
Monad m => Monad (Coyoneda m) Source # | |||||
MonadPlus f => MonadPlus (Coyoneda f) Source # | |||||
Comonad w => Comonad (Coyoneda w) Source # | |||||
Distributive f => Distributive (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Alt f => Alt (Coyoneda f) Source # | |||||
Apply f => Apply (Coyoneda f) Source # | |||||
Bind m => Bind (Coyoneda m) Source # | |||||
Extend w => Extend (Coyoneda w) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Plus f => Plus (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Traversable1 f => Traversable1 (Coyoneda f) Source # | |||||
Adjunction f g => Adjunction (Coyoneda f) (Coyoneda g) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
Read (f a) => Read (Coyoneda f a) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
(Functor f, Show1 f, Show a) => Show (Coyoneda f a) Source # | |||||
(Eq1 f, Eq a) => Eq (Coyoneda f a) Source # | |||||
(Ord1 f, Ord a) => Ord (Coyoneda f a) Source # | |||||
Defined in Data.Functor.Coyoneda | |||||
type Rep (Coyoneda f) Source # | |||||
Defined in Data.Functor.Coyoneda type Rep (Coyoneda f) = Rep f |
liftCoyoneda :: f a -> Coyoneda f a Source #
Yoneda "expansion"
liftCoyoneda
.lowerCoyoneda
≡id
lowerCoyoneda
.liftCoyoneda
≡id
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
hoistCoyoneda :: (forall a. f a -> g a) -> Coyoneda f b -> Coyoneda g b Source #
Lift a natural transformation from f
to g
to a natural transformation
from Coyoneda f
to Coyoneda g
.
as a Left Kan extension
coyonedaToLan :: forall (f :: Type -> Type) a. Coyoneda f a -> Lan Identity f a Source #
Coyoneda f
is the left Kan extension of f
along the Identity
functor.
Coyoneda f
is always a functor, even if f
is not. In this case, it
is called the free functor over f
. Note the following categorical fine
print: If f
is not a functor, Coyoneda f
is actually not the left Kan
extension of f
along the Identity
functor, but along the inclusion
functor from the discrete subcategory of Hask which contains only identity
functions as morphisms to the full category Hask. (This is because f
,
not being a proper functor, can only be interpreted as a categorical functor
by restricting the source category to only contain identities.)
coyonedaToLan
.lanToCoyoneda
≡id
lanToCoyoneda
.coyonedaToLan
≡id
lanToCoyoneda :: forall (f :: Type -> Type) a. Lan Identity f a -> Coyoneda f a Source #