In the following code, the where value= clause returns a partially applied function.
How can I ensure it gets fully applied?
------------------------------
future_value :: Float -> Float -> Float -> Float
future_value present interest periods =
(present * (( 1 + interest) ** periods))
------------------------------
-- Given an initial amount
-- Given a yearly fee, as well as a yearly interest...
-- Calculates return over a number of years, given a yearly fee.
return_over_time :: Float -> Float -> Float -> Float -> Float
return_over_time present interest num_years fee =
if num_years == 1 then (future_value present interest 1.0) - fee
else future_value value
where value = return_over_time present interest (num_years - 1) fee
The issue isn’t with
valuebut withfuture_value.future_valuetakes three arguments but you only give it one (value), sofuture_value valuehas the typeFloat -> Float - > Float.value, on the other hand, is just aFloatbecausereturn_over_timeis fully applied in thewhereclause.You can make sure
future_valueis fully applied by passing in two more floats forinterestandperiods.Incidentally, is there any particular reason you are using
Floatinstead ofDouble?