-
-
Save tkersey/00822646ca5af92204526e545a24107b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Yoneda -------------------------------------------------------------- | |
newtype Yoneda f a = Yoneda { runYoneda :: forall b. ((a -> b) -> f b) } | |
instance Functor (Yoneda f) where | |
fmap f y = Yoneda (\ab -> runYoneda y (ab . f)) | |
toYoneda :: Functor f => f a -> Yoneda f a | |
toYoneda fa = Yoneda (\f -> fmap f fa) | |
fromYoneda :: Yoneda f a -> f a | |
fromYoneda y = runYoneda y id | |
-- Coyoneda ----------------------------------------- | |
data CoYoneda f a = forall b . CoYoneda (b -> a) (f b) | |
instance Functor (CoYoneda f) where | |
fmap f (CoYoneda mp fb) = CoYoneda (f . mp) fb | |
toCoYoneda :: f a -> CoYoneda f a | |
toCoYoneda fa = CoYoneda id fa | |
fromCoYoneda :: Functor f => CoYoneda f a -> f a | |
fromCoYoneda (CoYoneda mp fb) = fmap mp fb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment