在OCaml中,当我传递应该有效的参数到
首先,我定义了一个用于记录日志的函数:
一切似乎都很好,但然后我得到了这个:
尽管以下内容有效:
Printf.printf
时,出现了一个我不理解的错误。这可能是因为我并没有完全理解该函数,但我无法确定哪里出了问题。首先,我定义了一个用于记录日志的函数:
utop # let log verbosity level str =
if level <= verbosity then (
Printf.printf "\nLevel %i: " level;
Printf.printf str);;
val log : int -> int -> (unit, out_channel, unit) format -> unit = <fun>
一切似乎都很好,但然后我得到了这个:
utop # log 0 0 "%i" 0;;
Error: This function has type
int -> int -> (unit, out_channel, unit) format -> unit
It is applied to too many arguments; maybe you forgot a `;'.
尽管以下内容有效:
utop # Printf.printf;;
- : ('a, out_channel, unit) format -> 'a = <fun>
utop # Printf.printf "%i" 0;;
0- : unit = ()
那么,我如何定义一个函数来执行log
的意图?
编辑:实际上,log 0 0 "%i" 0;;
看起来参数太多了(4个而不是3个),但Printf.printf "%i" 0;;
也是这样(2个而不是1个),它仍然可以工作。通过部分应用,可以得到以下结果:
utop # Printf.printf "%i";;
- : int -> unit = <fun>
utop # log 0 0 "%i";;
Error: This expression has type (unit, unit) CamlinternalFormatBasics.precision
but an expression was expected of type
(unit, int -> 'a) CamlinternalFormatBasics.precision
Type unit is not compatible with type int -> 'a