Skip to content

Instantly share code, notes, and snippets.

@jhickner
Last active December 14, 2015 11:39
Show Gist options
  • Save jhickner/5081100 to your computer and use it in GitHub Desktop.
Save jhickner/5081100 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RecordWildCards #-}
import Data.Monoid
data SalaryConfig = SalaryConfig
{ sAllowances :: Bool
, sBonus :: Bool
, sTax :: Bool
, sSurcharge :: Bool
}
defaultConfig = SalaryConfig True True True True
salary :: SalaryConfig -> Double -> Double
salary SalaryConfig{..} = appEndo fns
where fns = mconcat $ zipWith (\p fn -> if p then Endo fn else mempty)
[sAllowances, sBonus, sTax, sSurcharge]
[(*1.2), (*1.1), (*0.7), (*0.9)]
-- salary defaultConfig 20 -- 16.632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment