Skip to content

Instantly share code, notes, and snippets.

@fronx
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save fronx/a83cf1136d5bb5fc2d90 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/a83cf1136d5bb5fc2d90 to your computer and use it in GitHub Desktop.

Revisions

  1. fronx revised this gist Sep 14, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PairFunctors.hs
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,6 @@ instance Functor (Snd a) where
    fmap f (Snd (x, y)) = Snd (x, f y)

    main = do
    let pair = (3, 4) :: (Int, Int)
    let pair = (3, 4)
    print $ fmap (*2) $ Fst pair -- Fst (6, 4)
    print $ fmap (*2) $ Snd pair -- Snd (3, 8)
    print $ fmap (*2) $ Snd pair -- Fst (3, 8)
  2. fronx created this gist Sep 14, 2014.
    17 changes: 17 additions & 0 deletions PairFunctors.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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) :: (Int, Int)
    print $ fmap (*2) $ Fst pair -- Fst (6, 4)
    print $ fmap (*2) $ Snd pair -- Snd (3, 8)