From: "Jérémie Dimino" <jeremie@dimino.org>
To: Tiphaine Turpin <Tiphaine.Turpin@irisa.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] printf "%a" vs sprintf "%a"
Date: Thu, 26 Mar 2009 18:29:54 +0100 [thread overview]
Message-ID: <1238088594.8677.26.camel@localhost.localdomain> (raw)
In-Reply-To: <49CBB2F4.6000000@irisa.fr>
Tiphaine Turpin wrote:
> has type string. But %a breaks this rule. Wouldn't it be simpler to have
> two separate directives which accept respectively string printers and
> channel printers, regardless of the outer printing function ?
Note that you can do it with batteries and the new printf.
The default "%a" directive always uses a channel printer:
# Print.printf p"%a";;
- : (unit Batteries.IO.output -> '_a -> unit) -> '_a -> unit = <fun>
# Print.sprintf p"%a";;
- : (unit Batteries.IO.output -> '_a -> unit) -> '_a -> string = <fun>
And you can define a "%foo" directive which always uses a string printer:
# let printer_foo k f x = k (fun out -> String.print out (f x));;
val printer_as : (('a Batteries.IO.output -> unit) -> 'b) -> ('c -> string) -> 'c -> 'b = <fun>
# Print.printf p"%foo";;
- : ('_a -> string) -> '_a -> unit = <fun>
# Print.sprintf p"%foo";;
- : ('_a -> string) -> '_a -> string = <fun>
Cheers,
Jérémie
next prev parent reply other threads:[~2009-03-26 17:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-26 16:53 Tiphaine Turpin
2009-03-26 17:29 ` [Caml-list] " David Rajchenbach-Teller
2009-03-26 17:29 ` Jérémie Dimino [this message]
2009-03-26 17:37 ` Tiphaine Turpin
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=1238088594.8677.26.camel@localhost.localdomain \
--to=jeremie@dimino.org \
--cc=Tiphaine.Turpin@irisa.fr \
--cc=caml-list@yquem.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