Created
August 4, 2014 11:50
-
-
Save joshy/3b9e11591f994eda71af to your computer and use it in GitHub Desktop.
Functor example from FP Complete
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
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