Version française
Home     About     Download     Resources     Contact us    
Browse thread
printf "%a" vs sprintf "%a"
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tiphaine Turpin <Tiphaine.Turpin@i...>
Subject: Re: [Caml-list] printf "%a" vs sprintf "%a"
Thanks for the replies. sprintf2 is just fine for me.

Tiphaine


Jérémie Dimino a écrit :
> 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
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>