Created
January 21, 2020 18:37
-
-
Save folivetti/a0630e84087d7174cc69fc8c6a95bed8 to your computer and use it in GitHub Desktop.
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
module Main where | |
newtype Identity a = Id a deriving Show | |
data DoubleF a = DoubleF a a deriving Show | |
instance Functor Identity where | |
fmap f (Id a) = Id (f a) | |
instance Functor DoubleF where | |
fmap f (DoubleF x y) = DoubleF (f x) (f y) | |
-- it is isomorphic to | |
-- diag :: a -> (a, a) | |
-- diag x = (x, x) | |
diag :: Identity a -> DoubleF a | |
diag (Id x) = DoubleF x x | |
x :: Identity Int | |
x = Id 10 | |
-- Part (a) | |
-- (diag . fmap f) x == (fmap f . diag) x | |
-- diag $ fmap f x == fmap f (diag x) | |
-- diag $ (f x) == fmap f (x,x) | |
-- (f x, f x) == (f x, f x) | |
main = do | |
print $ (diag . fmap show) x | |
print $ (fmap show . diag) x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment