* Printf issues
@ 2007-03-16 18:34 Till Varoquaux
2007-03-17 11:56 ` [Caml-list] " Philippe Wang
2007-03-17 13:31 ` Nicolas Pouillard
0 siblings, 2 replies; 3+ messages in thread
From: Till Varoquaux @ 2007-03-16 18:34 UTC (permalink / raw)
To: ocaml ml
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?
Cheers,
Till
PS: This affects Ocaml 3.9.03 and 3.10 beta, Format and Printf...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Printf issues
2007-03-16 18:34 Printf issues Till Varoquaux
@ 2007-03-17 11:56 ` Philippe Wang
2007-03-17 13:31 ` Nicolas Pouillard
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Wang @ 2007-03-17 11:56 UTC (permalink / raw)
To: Till Varoquaux; +Cc: ocaml ml
Till Varoquaux 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?
Probably because it's not meant to be as you want it to be!
Why should sprintf take a function to output something on a channel
whereas it's used to return a string?
...
Cheers,
Philippe
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Printf issues
2007-03-16 18:34 Printf issues Till Varoquaux
2007-03-17 11:56 ` [Caml-list] " Philippe Wang
@ 2007-03-17 13:31 ` Nicolas Pouillard
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Pouillard @ 2007-03-17 13:31 UTC (permalink / raw)
To: Till Varoquaux; +Cc: ocaml ml
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-03-17 13:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-16 18:34 Printf issues Till Varoquaux
2007-03-17 11:56 ` [Caml-list] " Philippe Wang
2007-03-17 13:31 ` Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox