printingtypesoutputocamlformat-string

Trouble with printing a string in OCaml


The code compiles without the print statement. However with the print statement I get the error on that line that Error: This expression has type unit but an expression was expected of type int. I've also tried 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;;

Solution

  • There is a semicolon missing at the end of the Printf line.

    An alternative os the start this line with let () = and end it with in.