Skip to content

Instantly share code, notes, and snippets.

@christianwish
Last active January 10, 2019 14:56
Show Gist options
  • Save christianwish/12c859f74c74ce61422b95821545e312 to your computer and use it in GitHub Desktop.
Save christianwish/12c859f74c74ce61422b95821545e312 to your computer and use it in GitHub Desktop.
Functor hs
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