Created
October 29, 2015 17:14
-
-
Save theraphim/c3b86ab4e795e0994e8c to your computer and use it in GitHub Desktop.
This file contains 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
{-#LANGUAGE ScopedTypeVariables#-} | |
import Text.Read | |
import System.IO | |
prompt :: String -> IO String | |
prompt text = do | |
putStr text | |
hFlush stdout | |
getLine | |
maybePrompt :: (Read a) => String -> IO (Maybe a) | |
maybePrompt text = fmap readMaybe $ prompt text | |
rateHours :: Float -> Float -> Float | |
rateHours hours rate = if hours > 40 | |
then (hours - 40) * rate * 1.5 + 40 * rate | |
else hours * rate | |
main :: IO () | |
main = do | |
maybeHours :: Maybe Float <- maybePrompt "Enter hours: " | |
case maybeHours of | |
Just hours -> do | |
maybeRate :: Maybe Float <- maybePrompt "Enter rate: " | |
case maybeRate of | |
Just rate -> putStrLn $ show $ rateHours rate hours | |
Nothing -> putStrLn "Rate must be float" | |
Nothing -> putStrLn "Hours must be float" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment