From: Brian Hurt <bhurt@janestcapital.com>
To: caml-list@yquem.inria.fr
Subject: ifprint and format type question
Date: Wed, 23 Apr 2008 16:42:45 -0400 [thread overview]
Message-ID: <480F9F45.4040101@janestcapital.com> (raw)
So, I'm trying to write code like (simplifying):
let my_output (_: string) = ();; (* the real code is much more
complicated but not relevant *)
let foo b fmt =
if not b then
Printf.ifprintf () fmt
else
Printf.ksprintf my_output fmt
;;
The problem is that the above code doesn't compile- ifprintf wants fmt
to be ('b, unit, unit) format = ('b, unit, unit, unit) format4, while
ksprintf wants it to be ('b, unit, string, 'a) format4. Now, I could do
the above like:
let foo b fmt =
Printf.ksprintf (fun s -> if b then my_output s) fmt
but the point and purpose of using ifprintf is to avoid the cost of
converting the arguments to strings that are just going to be thrown away.
So, my questions are:
1: is there a way to make this work without using Obj.magic or
rewritting isprintf?
2: is there a reason ifprintf has the type 'a -> ('b, 'a, unit) format
-> 'b, instead of ('b, 'a, 'c) format -> 'b, or better yet ('b, 'a, 'c,
'd) format4 -> 'b, or even better yet ('b, 'a, 'c, 'd, 'e, 'f) format6
-> 'b (allowing it to unify with more different formats)?
3: Does ifprintf actually avoid the cost of converting it's arguments to
strings? The code is unclear. If the answer to this is 'no', the other
two questions are moot.
Brian
next reply other threads:[~2008-04-23 20:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-23 20:42 Brian Hurt [this message]
2008-04-24 8:39 ` [Caml-list] " Nicolas Pouillard
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=480F9F45.4040101@janestcapital.com \
--to=bhurt@janestcapital.com \
--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;
as well as URLs for NNTP newsgroup(s).