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

And I would hope 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?

3
  • 1
    For this specific case you can just use Printf.printf, right? Sep 9, 2013 at 22:07
  • let p = Printf.fprintf stdout;; p "%s" "string" works for me
    – newacct
    Sep 10, 2013 at 1:14
  • The '_a is weak polymorphism, which if fine, but if it is an error it usually means you need to eta-expand.
    – nlucaroni
    Sep 10, 2013 at 13:57

1 Answer 1

1

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

let p fmt = Printf.fprintf stdout fmt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.