I'm trying to write a version of Printf.printf
that always appends a newline character after writing its formatted output. My first attempt was
# let say fmt = Printf.ksprintf print_endline fmt;;
val say : ('a, unit, string, unit) format4 -> 'a = <fun>
The type signature looks right and say
works as expected. I noticed that fmt
is listed twice, and thought that partial application could eliminate it. So I tried this instead:
# let say = Printf.ksprintf print_endline;;
val say : ('_weak1, unit, string, unit) format4 -> '_weak1 = <fun>
The function definition looks cleaner, but the type signature looks wrong and say
no longer works as expected. For example, say
doesn't type check if the format string needs a variable number of arguments: I get an error that say
"is applied to too many arguments".
I can use the let say fmt = …
implementation, but why doesn't partial application work?