ocamlcaml

What does the Syntax error : operator expected mean in caml?


So I was writing my code to make a certain loop but I got that error when running it and don't understand why... Can someone explain me what's the problem here please.

for k = 0 to 10 do
for i = 0 to 10 do (let a = ref 0 ; a := !a + k*i mod 17) done ;
!a ;
done ;;

And here the error message :

# for k = 0 to 10 do
Line 4, characters 57-58:
4 |  for i = 0 to 10 do (let a = ref 0 ; a := !a + k*i mod 17); done ;
                                                         ^
Error: Syntax error: operator expected.

Solution

  • Granted it's not a very enlightening error message. However your problem is that you have let with no maching in. Except at the outermost level of a module, every let must be matched by in.

    You can change let a = ref 0 ; to let a = ref 0 in and should get a little farther.

    There are some other problems here, but this is your immediate problem, I think.