We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8450688 commit 4863951Copy full SHA for 4863951
Haskell/maybe.hs
@@ -0,0 +1,19 @@
1
+import Prelude hiding (Maybe(..), Functor, fmap, (<$>))
2
+
3
+data Maybe a = Just a | Nothing
4
+ deriving (Show)
5
6
+class Functor f where
7
+ fmap :: (a -> b) -> f a -> f b
8
9
+(<$>) :: Functor f => (a -> b) -> f a -> f b
10
+(<$>) = fmap
11
+infixl 4 <$>
12
13
+instance Functor Maybe where
14
+ fmap f (Just x) = Just $ f x
15
+ fmap _ Nothing = Nothing
16
17
+main = do
18
+ print $ (* 2) <$> Just 5
19
+ print $ (* 2) <$> Nothing
0 commit comments