创建传递两个参数的元素列表以创建它

Create a list of elements passing two params to create it

我正在研究 Caml 光。 我正在做很多练习。其中之一是创建一个函数来构建一个列表,将数字元素作为参数传递给复制.

我的密码是

let rec rep n x = if n >= 0 then x::(rep n-1 x) ;;

我在 n-1 上遇到了这个错误:

This expression is not a function, it cannot be applied.

我不明白为什么以及如何在每次递归调用时正确地递减该数字。

您需要在 n-1 周围加上括号,例如 (n-1)