diff --git a/src/NetPresentValue.hs b/src/NetPresentValue.hs index c8469dad958a002cb9110aa64ef6918a40212627..af73ac8c4961f693f73a9c38ef6312c9909d4397 100644 --- a/src/NetPresentValue.hs +++ b/src/NetPresentValue.hs @@ -28,20 +28,26 @@ data InputNetPresentValue = InputNetPresentValue calculateNetPresentValue :: InputNetPresentValue -> Double calculateNetPresentValue inputNetPresentValue = netPresentValue inputNetPresentValue +-- high order function netPresentValue inputNetPresentValue = foldl (+) 0 pv where pv = presentValue inputNetPresentValue +-- high order function presentValue inputNetPresentValue = zipWith (*) (netcashflow income outcome) (factorpresentvalue (project_interest inputNetPresentValue)) where income = [income_1 inputNetPresentValue, income_2 inputNetPresentValue, income_3 inputNetPresentValue, income_4 inputNetPresentValue, income_5 inputNetPresentValue] outcome = [outcome_1 inputNetPresentValue, outcome_2 inputNetPresentValue, outcome_3 inputNetPresentValue, outcome_4 inputNetPresentValue, outcome_5 inputNetPresentValue] -netcashflow a b = zipWith (-) a b +-- currying +netcashflow = zipWith (-) +-- recursion power n 1 = n power n m = n * (power n (m-1)) +-- recursion powervalue interest n = 1 / (power (1 + interest) n) +-- high order function factorpresentvalue interest = map (\x -> powervalue interest x) [1..5]