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:17] nikolaj |
maybe [2014/09/15 20:19] (current) nikolaj |
||
---|---|---|---|
Line 6: | Line 6: | ||
instance Monad Maybe where | instance Monad Maybe where | ||
- | return x = Just x | ||
(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 | + | instance Functor Maybe where |
- | -- fmap _ Nothing = Nothing | + | fmap _ Nothing = Nothing |
- | -- fmap f (Just a) = Just (f a) | + | fmap f (Just a) = Just (f a) |
</code> | </code> | ||