在 OCaml 中打印字符串时遇到问题
Trouble with printing a string in OCaml
代码在没有 print 语句的情况下编译。但是,对于打印语句,我在 Error: This expression has type unit but an expression was expected of type int
这一行得到了错误。我也试过 print_string numDigits
let rec rev_int num =
if num / 10 == 0 then
num
else
let temp = num mod 10 in
let numDigits = string_of_int num in
Printf.printf "%s" numDigits
let num = (num - temp) / 10 in
temp * (10 * String.length(numDigits)) + rev_int num;;
Printf 行末尾缺少一个分号。
另一个选择 os 以 let () =
开始这一行并以 in
结束。
代码在没有 print 语句的情况下编译。但是,对于打印语句,我在 Error: This expression has type unit but an expression was expected of type int
这一行得到了错误。我也试过 print_string numDigits
let rec rev_int num =
if num / 10 == 0 then
num
else
let temp = num mod 10 in
let numDigits = string_of_int num in
Printf.printf "%s" numDigits
let num = (num - temp) / 10 in
temp * (10 * String.length(numDigits)) + rev_int num;;
Printf 行末尾缺少一个分号。
另一个选择 os 以 let () =
开始这一行并以 in
结束。