Last active
August 29, 2015 14:06
-
-
Save fronx/a83cf1136d5bb5fc2d90 to your computer and use it in GitHub Desktop.
Pair has two functors
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
module PairFunctors where | |
data Fst b a = Fst (a, b) | |
deriving Show | |
data Snd a b = Snd (a, b) | |
deriving Show | |
instance Functor (Fst b) where | |
fmap f (Fst (x, y)) = Fst (f x, y) | |
instance Functor (Snd a) where | |
fmap f (Snd (x, y)) = Snd (x, f y) | |
main = do | |
let pair = (3, 4) | |
print $ fmap (*2) $ Fst pair -- Fst (6, 4) | |
print $ fmap (*2) $ Snd pair -- Fst (3, 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment