Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Proof of the functor laws for the Maybe functor
- fmap :: (a -> b) -> Maybe a -> Maybe b
- fmap f (Just x) = Just (f x)
- fmap f Nothing = Nothing
- Prove:
- fmap id = id
- Case 1: Just x
- fmap id (Just x)
- = Just (id x)
- = Just x
- Case 2: Nothing
- fmap id Nothing
- = Nothing
- Prove:
- fmap (g . f) = fmap g . fmap f
- Case 1: Just a
- fmap (g . f) (Just a)
- = Just (g . f $ a)
- = Just (g(f a))
- (fmap g . fmap f) (Just a)
- = fmap g (fmap f (Just a))
- = fmap g (Just (f a))
- = Just (g(f a))
- Case 2: Nothing
- (fmap g . fmap f) Nothing
- = fmap g (fmap f Nothing)
- = fmap g Nothing
- = Nothing
- fmap (g . f) Nothing
- = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement