Only parentheses are missing.
# print_string String.sub palavra i (tamanho-i);;
Error: This function has type string -> unit
It is applied to too many arguments; maybe you forgot a `;'.
You need parentheses around the argument of print_string
.
let palavra="1234567";;
let tamanho=String.length palavra;;
for i = 0 to 6 do
print_string (String.sub palavra i (tamanho-i));
print_string "\n";
done;;
Instead of print_string "\n"
, is easier to use print_endline
.
To make code more general, use length as the cycle terminal.
for i = 0 to tamanho do
print_endline (String.sub palavra i (tamanho-i));
done;;