The following code runs with no errors:
let f x y =
print_int (max x y);
print_char ' ';
print_int (x + y) in
for i = 1 to Scanf.scanf "%d" (fun x -> x) do
Scanf.scanf "\n%d %d" f;
print_newline ();
done;
But when I declare a variable fmt to hold the format "\n%d %d" and pass it to scanf,I get an error,here is the new code:
let f x y =
print_int (max x y);
print_char ' ';
print_int (x + y) in
let fmt = "\n%d %d" in (* added *)
for i = 1 to Scanf.scanf "%d" (fun x -> x) do
Scanf.scanf fmt f; (* edited *)
print_newline ();
done;
I get this error:
File "prog.ml", line 7, characters 16-19:
Error: This expression has type string but an expression was expected of type
('a, Scanf.Scanning.in_channel, 'b, 'c -> 'd, 'a -> 'e, 'e) format6
Why does it work differently?is there any difference between the two codes?