From 1f29b55821277fa11109a90a9a9753d62b81ae33 Mon Sep 17 00:00:00 2001 From: Ari Angga Nugraha <ari.angga@ui.ac.id> Date: Sat, 26 Dec 2020 00:24:27 +0700 Subject: [PATCH] add comment --- src/NetPresentValue.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NetPresentValue.hs b/src/NetPresentValue.hs index c8469da..af73ac8 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] -- GitLab