March 2019
Intermediate to advanced
208 pages
5h 11m
English
The authors of toFixedWithPrecision wanted you to be able to use that function without ever having to remember whether the number of digits was the first or the last parameter. Similarly, there is nothing wrong with the payment function, but it would be nice if people using it did not have to remember the order of the parameters. ReasonML lets you label parameters by preceding the parameter names with the ~ character. Here’s the payment function with labeled parameters:
| | let payment = (~principal, ~apr, ~years) => { |
| | let r = apr /. 12.0 /. 100.0; |
| | let n = float_of_int(years * 12); |
| | let powerTerm = (1.0 +. r) ** n; |
| | principal *. (r *. powerTerm) ... |
Read now
Unlock full access