Skip to content

Instantly share code, notes, and snippets.

@cwvh
Created May 15, 2014 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwvh/9f6b2323eefec7070e0e to your computer and use it in GitHub Desktop.
Save cwvh/9f6b2323eefec7070e0e to your computer and use it in GitHub Desktop.
bifunctors
data Gabuzomeu a b = Gabu a | Zomeu b
deriving Show
shadok :: (a -> c) -> (b -> d) -> Gabuzomeu a b -> Gabuzomeu c d
shadok f _ (Gabu a) = Gabu (f a)
shadok _ g (Zomeu b) = Zomeu (g b)
newtype G b a = G {first :: Gabuzomeu a b}
deriving Show
instance Functor (G b) where
fmap f = G . shadok f id . first
-- Written explicitly, the above looks like this:
--
-- fmap f (G (Gabu x)) = G (Gabu (f x))
newtype Z a b = Z {second :: Gabuzomeu a b}
deriving Show
instance Functor (Z a) where
fmap f = Z . shadok id f . second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment