Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement