I wasn't able to find a clear answer on Google, but it seems multiline if-statements are discouraged in OCaml (?) The ones I see with more line seem to have begin end keywords in them.
I'm currently getting this error on the line num = (num - temp) / 10, characters 25-27 : Error: Parse error: "end" expected after [sequence] (in [expr]). If I remove all of the begin end then I get the error Error: This expression has type bool but an expression was expected of type int at the same line.
let rec reverse_int num =
if num / 10 == 0 then begin
num
end else begin
let temp = num mod 10 in
num = (num - temp) / 10
let numDigits = string_of_int num
temp * (10 * String.length(numDigits)) + rev_int num
end;;
Aucun commentaire:
Enregistrer un commentaire