OCaml - for a loop inside an If statement

Based on the background of Java and C, understanding some of the concepts of Ocaml was quite interesting. One of them is getting the / multiple statement for the loop inside the loop.

let test_method (x: vector list) (vec: vector) = 
    if List.length x! = 0 then
          {a = 0.; b = 0.} (* Return a vector of 0,0 *)
       else 
          for i = 0 to List.length x do
                        let key = {a = (List.nth xi) .a; b = (List.nth xi) .b} 
                done ;;

the error I receive is made ;; is an unexpected token. Why is this happening? it happens even if i do it

let test_method (x: vector list) (vec: vector) = 
    if List.length x! = 0 then
          {a = 0.; b = 0.} (* Return a vector of 0,0 *)
       else 
          for i = 0 to List.length x do
                        let key = {a = (List.nth xi) .a; b = (List.nth xi) .b} in
                        let value = vec_neg key;
                done ;;

where vec_neg is a method that works great, which negates the vector type.

.

+3
2

let . (.. let var = val in body) ( , , ) let , . , (.. )? , . A let , . .

+3

, let foo = bar, in "". in, done, "".

let in, .

+1

Source: https://habr.com/ru/post/1720147/


All Articles