Skip to content

Instantly share code, notes, and snippets.

@monzou
Created July 7, 2012 07:35
Show Gist options
  • Save monzou/3065249 to your computer and use it in GitHub Desktop.
Save monzou/3065249 to your computer and use it in GitHub Desktop.
-- タプルの第一要素に 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