Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type monthlyInterestRate = | MonthlyInterestRate(float);
- type monthlyPaymentsRemaining = | MonthlyPaymentsRemaining(int);
- type amountBorrowed = | AmountBorrowed(float);
- type mortgageCalculator = {
- monthlyInterestRate: float,
- monthlyPaymentsRemaining: int,
- amountBorrowed: float
- };
- let calcWithRecord = (mc) => {
- (mc.monthlyInterestRate *. mc.amountBorrowed) /. (1.0 -. (1.0 +. mc.monthlyInterestRate) ** (-1.0 *. float_of_int(mc.monthlyPaymentsRemaining)))
- };
- let calcWithUnion = (mir, mpr, ab) => {
- let local_mir = switch mir {
- | MonthlyInterestRate(mir) => mir
- };
- let local_mpr = switch mpr {
- | MonthlyPaymentsRemaining(nmp) => nmp
- };
- let local_ab = switch ab {
- | AmountBorrowed(ab) => ab
- };
- (local_mir *. local_ab) /. (1.0 -. (1.0 +. local_mir) ** (-1.0 *. float_of_int(local_mpr)))
- };
- let mc = {
- monthlyInterestRate: 0.003,
- monthlyPaymentsRemaining: 12 * 30,
- amountBorrowed: 200000.0
- };
- Js.log(calcWithRecord(mc));
- Js.log(calcWithUnion(MonthlyInterestRate(0.003), MonthlyPaymentsRemaining(12 * 30), AmountBorrowed(200000.0)));
Add Comment
Please, Sign In to add comment