Un atajo para "Printf.fprintf"

As I use a lot Printf.fprintf stdout ... in my programs, I would like to rename it by a shorter function. So I write:

let p = Printf.fprintf stdout

Y yo esperaría p "%s" "string" works. However, the compilation gives an error:

File "lib/utility.ml", line 27, characters 8-29:
Error: The type of this expression, ('_a, out_channel, unit) format -> '_a,
       contains type variables that cannot be generalized

Does anyone have an idea to rename it so that the application could be as simple as possible?

preguntado el 09 de septiembre de 13 a las 23:09

For this specific case you can just use Printf.printf, ¿derecho? -

let p = Printf.fprintf stdout;; p "%s" "string" funciona para mi -

Programas de '_a is weak polymorphism, which if fine, but if it is an error it usually means you need to eta-expand. -

1 Respuestas

I think it will work if you eta-expand your definition:

let p fmt = Printf.fprintf stdout fmt

Respondido el 09 de Septiembre de 13 a las 23:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.