Skip to content

Commit 4863951

Browse files
committed
Added first example
1 parent 8450688 commit 4863951

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Haskell/maybe.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)