Created
July 7, 2012 07:35
-
-
Save monzou/3065249 to your computer and use it in GitHub Desktop.
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
-- タプルの第一要素に fmap したいが, Functor は型引数を 1 つしか取れないので newtype を定義する | |
newtype Pair b a = Pair { getPair :: (a, b) } deriving (Show) | |
instance Functor (Pair c) where | |
fmap f (Pair (x, y)) = Pair (f x, y) | |
main = print $ fmap reverse(Pair ("foo", "bar")) -- Pair ("oof", "bar") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment