Advertisement
Guest User

Tax Program

a guest
Jul 22nd, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. --aliases for code understanding
  2. type Bracket = Float
  3. type BaseTax = Float
  4. type Percent = Float
  5.  
  6. --We don't care about income at this time, because the user will provide it
  7. --this data type maybe could just be used for everything?
  8. --is there a better way to do this?
  9. data Info = Info [Bracket] [BaseTax] Rate
  10. data Rate = Rate [Percent]
  11.  
  12. -- percentage taken out after base tax
  13. rates = Rate [0.0, 0.28, 0.31, 0.36, 0.396]
  14. -- info for various tax types
  15. married = Info [0, 36900, 89150, 140000, 250000] [0, 5535, 20165, 35928.5, 75528.5] rates
  16. hoh = Info [0, 29600, 76400, 127500, 250000] [0, 4440, 17544, 33385, 77485] rates
  17. unmarried = Info [0, 22100, 53500, 115000, 250000] [0, 3315, 12107, 31172, 79772] rates
  18. marrseper = Info [0, 18450, 44575, 70000, 125000] [0, 2767.5, 10085.5, 17964.25, 37764.25] rates
  19. estate = Info [0, 1500, 3500, 5500, 7500] [0, 225, 785, 1405, 2125] rates
  20.  
  21. --How do I compare income to the list? map filter (income) over Info?
  22. --I'm trying to compare the income to the Bracket field of the Info type.
  23. --I want to use the relevant fields for each bracket based upon the result
  24. --in C++ I'd create a class that contained each field, and directly reference that object when discovered
  25. --Return pair is the post tax income, the Bool is whether or not that is greater than post tax income in previous bracket
  26. getRaise :: Float -> Info -> (Float, Bool)
  27. getRaise income info =
  28. | income >= info
  29.  
  30.  
  31. --function works as intended, but may need to fix to accommodate taking only income (intent of function above)
  32. taxes :: Float -> Bracket -> BaseTax -> Percent -> Bool
  33. taxes income bracket c1 c2 = if over-c1 >= income - (c2*income - c2*c1 + c1)
  34. then False
  35. else True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement