Skip to content

Instantly share code, notes, and snippets.

@harukizaemon
Created August 17, 2009 09:10
Show Gist options
  • Save harukizaemon/169010 to your computer and use it in GitHub Desktop.
Save harukizaemon/169010 to your computer and use it in GitHub Desktop.
taxRate threshold rate (total, amount)
| amount > threshold = (total + (amount - threshold) * rate, threshold)
| otherwise = (total, 0)
taxTable = [taxRate 60000 0.45, taxRate 30000 0.30, taxRate 15000 0.15]
tax amount = fst (calc(0, amount) taxTable)
where calc (total, remainder) [] = (total, remainder)
calc (total, remainder) (f:fs) = calc (f (total, remainder)) fs
> tax 72000
=> 16500.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment