<commit_before>module Main (main) where

import Flow ((|>))
import System.Environment (getArgs, getProgName)
import Text.Printf (printf)

import MortgageCalc (calcMonthlyPayment, calcAmortization)

{- TODO
 - Prelude.read: no parse
 - exit code
 -}

main = getArgs >>= \args -> getProgName >>= \progName ->
  case args of
    [       loan, annualInterestRate, years ] ->
      let (l, i, n) = readArgs loan annualInterestRate years
      in calcMonthlyPayment l i n |> showMonthlyPayment n
    [ "-v", loan, annualInterestRate, years ] ->
      let (l, i, n) = readArgs loan annualInterestRate years
          p = calcMonthlyPayment l i n
          a = calcAmortization p l i n
      in showMonthlyPayment n p ++ showAmortization a
    otherwise                                 -> showUsage progName
  |> putStrLn

readArgs :: String -> String -> String -> (Float, Float, Int)
readArgs loan annualInterestRate years = (read loan, (read annualInterestRate) / 100, read years)

showMonthlyPayment :: Int -> Float -> String
showMonthlyPayment n p =
  printf "Your monthly payment is $%f, and the total payment is $%f." p (p * 12 * fromIntegral n)
<commit_msg>Tiny format fix.<commit_after>module Main (main) where

import Flow ((|>))
import System.Environment (getArgs, getProgName)
import Text.Printf (printf)

import MortgageCalc (calcMonthlyPayment, calcAmortization)

{- TODO
 - Prelude.read: no parse
 - exit code
 -}

main = getArgs >>= \args -> getProgName >>= \progName ->
  case args of
    [       loan, annualInterestRate, years ] ->
      let (l, i, n) = readArgs loan annualInterestRate years
      in calcMonthlyPayment l i n |> showMonthlyPayment n
    [ "-v", loan, annualInterestRate, years ] ->
      let (l, i, n) = readArgs loan annualInterestRate years
          p = calcMonthlyPayment l i n
          a = calcAmortization p l i n
      in showMonthlyPayment n p ++ showAmortization a
    otherwise                                 -> showUsage progName
  |> putStr

readArgs :: String -> String -> String -> (Float, Float, Int)
readArgs loan annualInterestRate years = (read loan, (read annualInterestRate) / 100, read years)

showMonthlyPayment :: Int -> Float -> String
showMonthlyPayment n p =
  printf "Your monthly payment is $%f, and the total payment is $%f.\n" p (p * 12 * fromIntegral n)

{'fraction_non_alphanumeric': 0.10194384449244061, 'fraction_numerical': 0.004319654427645789, 'mean_word_length': 2.9454855195911414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5000155', 'n_tokens_mistral': 714, 'n_tokens_neox': 679, 'n_words': 250}