Guest User

Untitled

a guest
Jan 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. type monthlyInterestRate = | MonthlyInterestRate(float);
  2. type monthlyPaymentsRemaining = | MonthlyPaymentsRemaining(int);
  3. type amountBorrowed = | AmountBorrowed(float);
  4.  
  5. type mortgageCalculator = {
  6. monthlyInterestRate: float,
  7. monthlyPaymentsRemaining: int,
  8. amountBorrowed: float
  9. };
  10.  
  11. let calcWithRecord = (mc) => {
  12. (mc.monthlyInterestRate *. mc.amountBorrowed) /. (1.0 -. (1.0 +. mc.monthlyInterestRate) ** (-1.0 *. float_of_int(mc.monthlyPaymentsRemaining)))
  13. };
  14.  
  15. let calcWithUnion = (mir, mpr, ab) => {
  16. let local_mir = switch mir {
  17. | MonthlyInterestRate(mir) => mir
  18. };
  19. let local_mpr = switch mpr {
  20. | MonthlyPaymentsRemaining(nmp) => nmp
  21. };
  22. let local_ab = switch ab {
  23. | AmountBorrowed(ab) => ab
  24. };
  25. (local_mir *. local_ab) /. (1.0 -. (1.0 +. local_mir) ** (-1.0 *. float_of_int(local_mpr)))
  26. };
  27.  
  28. let mc = {
  29. monthlyInterestRate: 0.003,
  30. monthlyPaymentsRemaining: 12 * 30,
  31. amountBorrowed: 200000.0
  32. };
  33.  
  34. Js.log(calcWithRecord(mc));
  35. Js.log(calcWithUnion(MonthlyInterestRate(0.003), MonthlyPaymentsRemaining(12 * 30), AmountBorrowed(200000.0)));
Add Comment
Please, Sign In to add comment