Skip to content

Instantly share code, notes, and snippets.

@dtoma
Created April 11, 2019 05:38
Show Gist options
  • Save dtoma/c1e1a3fe469cc14cdc47d48f6b8d9ff6 to your computer and use it in GitHub Desktop.
Save dtoma/c1e1a3fe469cc14cdc47d48f6b8d9ff6 to your computer and use it in GitHub Desktop.
impots
tranche :: Int -> Int -> Float -> Int -> Float
tranche min max taux revenu = if revenu > max then (max - min) * taux else (revenu - min) * taux
tranches :: [Int]
tranches = [0, 9807, 27086, 72617, 153783]
rates :: [Float]
rates = [0.0, 0.14, 0.30, 0.41, 0.45]
-- Jusqu'à 9 807 euros 0 %
t1 = tranche tranches!!0 tranches!!1 rates!!0
-- De 9 807 à 27 086 euros 14 %
t2 = tranche tranches!!1 tranches!!2 rates!!1
-- De 27 086 à 72 617 euros 30 %
t3 = tranche tranches!!2 tranches!!3 rates!!2
-- De 72 617 à 153 783 euros 41 %
t4 = tranche tranches!!3 tranches!!4 rates!!3
-- Au-dessus de 153 783 euros 45 %
t5 = tranche tranches!!4 (maxBound :: Int) rates!!4
funT = [t1, t2, t3, t4, t5]
getTranchesTax :: Int -> Int -> [Float]
getTranchesTax numT revenu = do
trancheAmount <- tranches!!numT
rest <- revenu - trancheAmount
case rest > 0 of
True -> [funT!!numT trancheAmount] ++ getTranchesTax (numT + 1) rest
False -> [funT!!numT revenu]
total = sum $ getTranchesTax 0 revenu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment