Last active
April 12, 2018 04:27
-
-
Save carlosgruiz-dev/de91dd018a4eeda546a0900df98604ef to your computer and use it in GitHub Desktop.
haskell script to show your reading progress of the haskellbook
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
#!/usr/bin/env stack | |
-- stack runghc --resolver lts-11.2 --install-ghc | |
import Text.Read (readMaybe) | |
import System.Environment (getArgs) | |
progress :: Integer -> String | |
progress pag = show $ fromIntegral ( div (pag * 10000) 1971) / 100 | |
showProgress :: [String] -> IO() | |
showProgress args = | |
case (readMaybe $ head args) of | |
Nothing -> putStrLn $ "Can't parse a page number from args\n\n" ++ usageMsg | |
Just page -> putStrLn ("You have completed " ++ (progress page) | |
++ "% of the book") | |
usageMsg :: String | |
usageMsg = ("Usage: hbprogress [the page you are reading]\n" | |
++ "note: n / 1971 in case of the e-reader version") | |
main :: IO() | |
main = do | |
args <- getArgs | |
if args == [] then | |
putStrLn usageMsg | |
else | |
showProgress args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment