-
-
Save cwvh/9f6b2323eefec7070e0e to your computer and use it in GitHub Desktop.
bifunctors
This file contains 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
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