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
所以这次修复上个类型的问题,但对于整个返回类型的功能? –