Created
February 27, 2012 06:57
-
-
Save dmatveev/1922080 to your computer and use it in GitHub Desktop.
A poor man's monad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(>>?) :: (Ord a, Num a) => Maybe a -> (a -> Maybe b) -> Maybe b | |
Nothing >>? _ = Nothing | |
Just v >>? f = if v > 0 then f v else Nothing | |
decr :: Int -> Maybe Int | |
decr a = Just (a - 1) | |
ex1 = (Just 1) >>? decr >>? decr >>? decr | |
ex2 = (Just 10) >>? decr >>? decr >>? decr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment