Skip to content

Instantly share code, notes, and snippets.

@theraphim
Created October 29, 2015 17:14
Show Gist options
  • Save theraphim/c3b86ab4e795e0994e8c to your computer and use it in GitHub Desktop.
Save theraphim/c3b86ab4e795e0994e8c to your computer and use it in GitHub Desktop.
{-#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