From: MAILER-DAEMON@kraid.nerim.net (Mail Delivery System)
To: damien.doligez@inria.fr
Subject: Re: [Caml-list] format4 query (Modified by Damien Doligez)
Date: Wed, 19 May 2004 19:20:43 +0200 (CEST) [thread overview]
Message-ID: <504F4A75-A9B9-11D8-A6E5-00039310CAE8@kraid.nerim.net> (raw)
On May 19, 2004, at 18:13, David J. Trombley wrote:
> Right, as I said I can get simple examples to work. But I
> can't get syntax such as
>
> # let g (l : listener) (k : int) fmt =
> match k with
> 0 -> 0
> | x -> Printf.kprintf l fmt; k;;
>
> val g : listener -> int -> ('a, unit, string, unit)
> format4 -> int = <fun>
>
> to function, as you can see the format type has been
> inferred to a type that is not useful at all.
>
> I'd like to use kprintf as a side effect to a function which
> evaluates to some type, but I would not like that type or
> the unit type of a ; evaluation to affect the format type.
Here is the trick: the call to kprintf must always be the last
thing that your function does. You get control back when kprintf
calls your continuation function:
let g (l : listener) (k : int) fmt =
let cont s =
match k with
| 0 -> 0
| _ -> l s; k
in
Printf.kprintf cont fmt
;;
Note that kprintf will be called in all cases, but that's
unavoidable because it has to consume the arguments that will
be passed to g after the fmt argument.
-- Damien
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
reply other threads:[~2004-05-19 17:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=504F4A75-A9B9-11D8-A6E5-00039310CAE8@kraid.nerim.net \
--to=mailer-daemon@kraid.nerim.net \
--cc=damien.doligez@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).