Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. Proof of the functor laws for the Maybe functor
  2.  
  3. fmap :: (a -> b) -> Maybe a -> Maybe b
  4. fmap f (Just x) = Just (f x)
  5. fmap f Nothing = Nothing
  6.  
  7. Prove:
  8. fmap id = id
  9.  
  10. Case 1: Just x
  11.  
  12. fmap id (Just x)
  13. = Just (id x)
  14. = Just x
  15.  
  16. Case 2: Nothing
  17.  
  18. fmap id Nothing
  19. = Nothing
  20.  
  21.  
  22. Prove:
  23. fmap (g . f) = fmap g . fmap f
  24.  
  25. Case 1: Just a
  26. fmap (g . f) (Just a)
  27. = Just (g . f $ a)
  28. = Just (g(f a))
  29.  
  30.  
  31. (fmap g . fmap f) (Just a)
  32. = fmap g (fmap f (Just a))
  33. = fmap g (Just (f a))
  34. = Just (g(f a))
  35.  
  36.  
  37. Case 2: Nothing
  38. (fmap g . fmap f) Nothing
  39. = fmap g (fmap f Nothing)
  40. = fmap g Nothing
  41. = Nothing
  42.  
  43. fmap (g . f) Nothing
  44. = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement