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
The error message is:
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
#
result := !result * !k
k:=!k+1
You're missing a semicolon at the end of the first line. Because of this it is read as:
result := !result * (!k k:=!k+1)
i.e. it thinks you're trying to call !k with k:=!k+1 as its argument.
This is also why your editor indented the line with k := !k+1 farther to the right than the line above it. That should have been the first sign that something's wrong with the syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With