* Re: [Caml-list] format4 query (Modified by Damien Doligez)
@ 2004-05-19 17:20 Mail Delivery System
0 siblings, 0 replies; only message in thread
From: Mail Delivery System @ 2004-05-19 17:20 UTC (permalink / raw)
To: damien.doligez
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-05-19 17:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-19 17:20 [Caml-list] format4 query (Modified by Damien Doligez) Mail Delivery System
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).