Skip to content

Instantly share code, notes, and snippets.

@mjwillson
Created October 29, 2009 22:35
Show Gist options
  • Save mjwillson/221903 to your computer and use it in GitHub Desktop.
Save mjwillson/221903 to your computer and use it in GitHub Desktop.
Pure functional tax bands
infinity = 1.0/0
savingsIncomeTax200910 = [(0, 6475), (0.1, 8915), (0.2, 43875), (0.4, infinity)]
incomeTax200910 = [(0, 6475), (0.2, 43875), (0.4, infinity)]
taxWithBands bands income
= if income <= threshold then
rate * income
else
rate * threshold + taxWithBands loweredRemainingBands remainingIncome
where
(rate, threshold) : remainingBands = bands
remainingIncome = income - threshold
loweredRemainingBands = map (\(r,t) -> (r, t-threshold)) remainingBands
-- *Main> taxWithBands incomeTax200910 1000000
-- 389930.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment