-
-
Save christianwish/12c859f74c74ce61422b95821545e312 to your computer and use it in GitHub Desktop.
Functor hs
This file contains hidden or 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 F where | |
data Mappable a = A a | B a deriving (Show, Eq) | |
instance Functor Mappable where | |
fmap f (A x) = A (f x) | |
fmap f (B x) = B (f x) | |
-- Usage | |
a = A 3 | |
main = do | |
let resultA = fmap (+ 2) a | |
resultB = (+ 2) <$> a | |
print resultA | |
print resultB | |
print $ if resultA == resultB then "Equal!" else "Not Equal" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment