Skip to content

Instantly share code, notes, and snippets.

@cwvh
Created May 15, 2014
Embed
What would you like to do?
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