Skip to content

Instantly share code, notes, and snippets.

@StevenXL
Created June 13, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenXL/313d368f9d8a5a1fdec884fd7bd51aa1 to your computer and use it in GitHub Desktop.
Save StevenXL/313d368f9d8a5a1fdec884fd7bd51aa1 to your computer and use it in GitHub Desktop.
Monads and Pure Functions
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