Skip to content

Instantly share code, notes, and snippets.

@joshy
Created August 4, 2014 11:50
Show Gist options
  • Save joshy/3b9e11591f994eda71af to your computer and use it in GitHub Desktop.
Save joshy/3b9e11591f994eda71af to your computer and use it in GitHub Desktop.
Functor example from FP Complete
import Safe (readMay)
display maybeAge =
case maybeAge of
Nothing -> putStrLn "Could not read input."
Just age -> putStrLn $ "In 2020, you will be: " ++ show age
yearToAge age = 2020 - age
main = do
putStrLn "Please enter your birth year"
yearString <- getLine
let maybeAge = fmap yearToAge (readMay yearString)
display maybeAge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment