Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
maybe [2014/09/15 20:14] nikolaj |
maybe [2014/09/15 20:19] nikolaj |
||
---|---|---|---|
Line 4: | Line 4: | ||
data Maybe a = Nothing | Just a | data Maybe a = Nothing | Just a | ||
deriving (Eq, Ord) | deriving (Eq, Ord) | ||
- | |||
- | instance Functor Maybe where | ||
- | fmap _ Nothing = Nothing | ||
- | fmap f (Just a) = Just (f a) | ||
instance Monad Maybe where | instance Monad Maybe where | ||
(Just x) >>= k = k x | (Just x) >>= k = k x | ||
Nothing >>= _ = Nothing | Nothing >>= _ = Nothing | ||
- | |||
- | (Just _) >> k = k | ||
- | Nothing >> _ = Nothing | ||
return = Just | return = Just | ||
fail _ = Nothing | fail _ = Nothing | ||
+ | |||
+ | -- utility | ||
+ | |||
+ | (Just _) >> k = k | ||
+ | Nothing >> _ = Nothing | ||
+ | | ||
+ | instance Functor Maybe where | ||
+ | fmap _ Nothing = Nothing | ||
+ | fmap f (Just a) = Just (f a) | ||
</code> | </code> | ||