From: Florian Angeletti <octa@polychoron.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Returning printf from a function
Date: Thu, 23 Aug 2018 11:28:59 +0200 [thread overview]
Message-ID: <e2c2e011-97f2-084b-c99c-ee26feca7466@polychoron.fr> (raw)
In-Reply-To: <20180823091552.vq5oizsushwfivgz@annexia.org>
This is the value restriction at work, you can avoid the issue by replacing
let printer = get_printer true in ...
where the type of printer is "Format.formatter -> ('_weak1,
Format.formatter, unit) format -> '_weak1", with
let printer x = get_printer true x in ...
− octachron.
On 23/08/2018 11:15, Richard W.M. Jones wrote:
> This is a problem we hit from time to time and I don't think I've ever
> really understood why it happens. This made up example shows the
> essence:
>
> ----------------------------------------------------------------------
> let get_printer out =
> if out then Printf.printf else Printf.fprintf stderr
>
> let () =
> let printer = get_printer true in
> printer "hello\n";
> printer "goodbye %s\n" "everyone" (* line 7 *)
> ----------------------------------------------------------------------
>
> $ ocamlopt test2.ml
> File "test2.ml", line 7, characters 2-9:
> Error: This function has type (unit, out_channel, unit) format -> unit
> It is applied to too many arguments; maybe you forgot a `;'.
>
> Type inference in line 6 seems to overspecify the inferred type of
> printer, so that we get the error on line 7.
>
> Why? And how to fix it?
>
> Rich.
>
next prev parent reply other threads:[~2018-08-23 9:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 9:15 Richard W.M. Jones
2018-08-23 9:28 ` Florian Angeletti [this message]
2018-08-23 9:48 ` Richard W.M. Jones
2018-08-23 10:08 ` Florian Angeletti
2018-08-23 10:23 ` Richard W.M. Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e2c2e011-97f2-084b-c99c-ee26feca7466@polychoron.fr \
--to=octa@polychoron.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox