#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
#endif
module Data.Functor.Contravariant.Yoneda
( Yoneda(..)
, liftYoneda, lowerYoneda
) where
import Data.Functor.Contravariant
import Data.Functor.Contravariant.Adjunction
import Data.Functor.Contravariant.Representable
newtype Yoneda f a = Yoneda { runYoneda :: forall r. (r -> a) -> f r }
liftYoneda :: Contravariant f => f a -> Yoneda f a
liftYoneda fa = Yoneda $ \ra -> contramap ra fa
lowerYoneda :: Yoneda f a -> f a
lowerYoneda f = runYoneda f id
instance Contravariant (Yoneda f) where
contramap ab (Yoneda m) = Yoneda (m . fmap ab)
type instance Value (Yoneda f) = Value f
instance Valued f => Valued (Yoneda f) where
contramapWithValue beav = liftYoneda . contramapWithValue beav . lowerYoneda
instance Coindexed f => Coindexed (Yoneda f) where
coindex m a = coindex (lowerYoneda m) a
instance Representable f => Representable (Yoneda f) where
contrarep = liftYoneda . contrarep
instance Adjunction f g => Adjunction (Yoneda f) (Yoneda g) where
leftAdjunct f = liftYoneda . leftAdjunct (lowerYoneda . f)
rightAdjunct f = liftYoneda . rightAdjunct (lowerYoneda . f)