Skip to content

Instantly share code, notes, and snippets.

@atmantree atmantree/hbprogress.hs
Last active Apr 12, 2018

Embed
What would you like to do?
haskell script to show your reading progress of the haskellbook
#!/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
You can’t perform that action at this time.