let impfac i =
let l = ref i in
let result = ref 1 in
let k = ref 2 in
while !k < !l do
result := !result * !k
k:=!k+1
done;
!result
错误消息是:
let impfac i =
let l = ref i in
let result = ref 1 in
let k = ref 2 in
while !k < !l do
result := !result * !k
k:=!k+1
done;
!result;;
Characters 121-123:
result := !result * !k
^^
Error: This expression is not a function; it cannot be applied
#
答案 0 :(得分:7)
result := !result * !k
k:=!k+1
你在第一行末尾错过了一个分号。因此,它被解读为:
result := !result * (!k k:=!k+1)
即。它认为你试图用!k
作为其论点来调用k:=!k+1
。
这也是为什么你的编辑器缩进了k := !k+1
的行,而不是它上面的行。这应该是语法错误的第一个迹象。