Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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