let rec calcTotalMonths ~moneyOwed:moneyOwed ~interestRate:interestRate ~monthlyPayment:monthlyPayment ~months:months=0 = (
let newBalance = (moneyOwed -. monthlyPayment) *. interestRate in
match newBalance <= 0. with
true -> months
| false -> calcTotalMonths newBalance interestRate monthlyPayment months+1
);;
我想知道爲什麼我一直得到不明白返回類型
File "budget.ml", line 19, characters 12-73:
Error: This expression has type
moneyOwed:float ->
interestRate:float -> monthlyPayment:float -> months:'a -> 'b
爲什麼幾個月類型「一當它清楚地使用‘+’操作符上幾個月。它也會在遞歸的基本情況下返回幾個月,所以它爲什麼是'b'作爲返回類型。
編輯: 做傑夫的建議
File "budget.ml", line 19, characters 12-77:
Error: This expression has type
moneyOwed:float ->
interestRate:float -> monthlyPayment:float -> months:int -> 'a
but an expression was expected of type int
所以這次修復上個類型的問題,但對於整個返回類型的功能? –