Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. -- Yoneda --------------------------------------------------------------
  2. newtype Yoneda f a = Yoneda { runYoneda :: forall b. ((a -> b) -> f b) }
  3.  
  4. instance Functor (Yoneda f) where
  5. fmap f y = Yoneda (\ab -> runYoneda y (ab . f))
  6.  
  7. toYoneda :: Functor f => f a -> Yoneda f a
  8. toYoneda fa = Yoneda (\f -> fmap f fa)
  9.  
  10. fromYoneda :: Yoneda f a -> f a
  11. fromYoneda y = runYoneda y id
  12.  
  13. -- Coyoneda -----------------------------------------
  14. data CoYoneda f a = forall b . CoYoneda (b -> a) (f b)
  15.  
  16. instance Functor (CoYoneda f) where
  17. fmap f (CoYoneda mp fb) = CoYoneda (f . mp) fb
  18.  
  19. toCoYoneda :: f a -> CoYoneda f a
  20. toCoYoneda fa = CoYoneda id fa
  21.  
  22. fromCoYoneda :: Functor f => CoYoneda f a -> f a
  23. fromCoYoneda (CoYoneda mp fb) = fmap mp fb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement