Un atajo para "Printf.fprintf"
Frecuentes
Visto 99 veces
2
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?
1 Respuestas
1
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 printing ocaml or haz tu propia pregunta.
For this specific case you can just use
Printf.printf
, ¿derecho? - Jeffrey Scofieldlet p = Printf.fprintf stdout;; p "%s" "string"
funciona para mi - newacctProgramas de
'_a
is weak polymorphism, which if fine, but if it is an error it usually means you need to eta-expand. - nlucaroni