Created
October 29, 2009 22:35
-
-
Save mjwillson/221903 to your computer and use it in GitHub Desktop.
Pure functional tax bands
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
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