Created
June 13, 2018 13:01
-
-
Save StevenXL/313d368f9d8a5a1fdec884fd7bd51aa1 to your computer and use it in GitHub Desktop.
Monads and Pure Functions
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
| module Monad where | |
| maxPairM :: (Monad m, Ord a) => m (a, a) -> m a | |
| maxPairM m = m >>= \p -> return (maxPair p) | |
| maxPairM' :: (Monad m, Ord a) => m (a, a) -> m a | |
| maxPairM' m = (return . maxPair) =<< m -- I like it because it looks like function composition | |
| maxPair :: Ord a => (a, a) -> a | |
| maxPair (f, s) = max f s | |
| wSugar :: IO () | |
| wSugar = do | |
| name <- getLine | |
| let statement = helloPerson name | |
| putStrLn statement | |
| noSugar :: IO () | |
| noSugar = getLine >>= \name -> putStrLn (helloPerson name) | |
| helloPerson :: String -> String | |
| helloPerson name = "Hello " ++ name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment