Created
April 23, 2017 15:59
-
-
Save vvviiimmm/88e01ca20cb8df627cef65c067622d78 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