From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Till Varoquaux" <till.varoquaux@gmail.com>
Cc: "ocaml ml" <caml-list@inria.fr>
Subject: Re: [Caml-list] Printf issues
Date: Sat, 17 Mar 2007 14:31:26 +0100 [thread overview]
Message-ID: <cd67f63a0703170631u1162bfc2n171b1421558681c1@mail.gmail.com> (raw)
In-Reply-To: <9d3ec8300703161134o3866014bie47bf052b20b722@mail.gmail.com>
On 3/16/07, Till Varoquaux <till.varoquaux@gmail.com> wrote:
> I having typing issues with sprintf:
>
> # Printf.sprintf "%a";;
> - : (unit -> '_a -> string) -> '_a -> string = <fun>
>
> whereas:
>
> # Printf.printf "%a";;
> - : (out_channel -> '_a -> unit) -> '_a -> unit = <fun>
>
> Am I missing something out here? If not why can't sprintf accept the
> same printers as the other?
That's specified this way. It's why I don't often use sprintf but
rather these one (mainly sbprintf):
module Format_plus :
sig
val ksbprintf : (string -> 'a) -> ('b, Format.formatter, unit, 'a)
format4 -> 'b
val sbprintf : ('a, Format.formatter, unit, string) format4 -> 'a
end =
struct
open Format
let ksbprintf g fmt =
let buff = Buffer.create 42 in
let f = formatter_of_buffer buff in
kfprintf (fun f -> (pp_print_flush f (); g (Buffer.contents buff))) f fmt
let sbprintf fmt = ksbprintf (fun x -> x) fmt
end
That way it's more uniform and I can reuse the same printers for
fprintf and sbprintf.
Hope this helps,
--
Nicolas Pouillard
prev parent reply other threads:[~2007-03-17 13:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-16 18:34 Till Varoquaux
2007-03-17 11:56 ` [Caml-list] " Philippe Wang
2007-03-17 13:31 ` Nicolas Pouillard [this message]
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=cd67f63a0703170631u1162bfc2n171b1421558681c1@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=caml-list@inria.fr \
--cc=till.varoquaux@gmail.com \
/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