* [Caml-list] Printf.sprintf "%a" @ 2016-07-08 8:01 Rodolphe Lepigre 2016-07-08 8:08 ` Nicolas Ojeda Bar 0 siblings, 1 reply; 5+ messages in thread From: Rodolphe Lepigre @ 2016-07-08 8:01 UTC (permalink / raw) To: caml-list Dear list, If I define two values val p : type out_channel -> blop -> unit val e : blop then I can do something like Printf.printf "%a" p e but I can't find a way to do something like Printf.sprintf "%a" p e which is not well-typed. Is there any trick that I can use to avoid changing the type of [p] to [blop -> string]? Cheers, Rodolphe -- Rodolphe Lepigre LAMA, Université Savoie Mont Blanc, FRANCE http://lama.univ-smb.fr/~lepigre/ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Printf.sprintf "%a" 2016-07-08 8:01 [Caml-list] Printf.sprintf "%a" Rodolphe Lepigre @ 2016-07-08 8:08 ` Nicolas Ojeda Bar 2016-07-08 8:16 ` Rodolphe Lepigre 0 siblings, 1 reply; 5+ messages in thread From: Nicolas Ojeda Bar @ 2016-07-08 8:08 UTC (permalink / raw) To: Rodolphe Lepigre; +Cc: OCaml Mailing List [-- Attachment #1: Type: text/plain, Size: 1013 bytes --] Hi Rodolphe, I don't think this is possible with Printf. But if you can switch to Format you can use Format.asprintf instead. Cheers, Nicolas On Fri, Jul 8, 2016 at 10:01 AM, Rodolphe Lepigre < rodolphe.lepigre@univ-savoie.fr> wrote: > Dear list, > > If I define two values > > val p : type out_channel -> blop -> unit > val e : blop > > then I can do something like > > Printf.printf "%a" p e > > but I can't find a way to do something like > > Printf.sprintf "%a" p e > > which is not well-typed. Is there any trick that I can use to avoid > changing the type of [p] to [blop -> string]? > > Cheers, > > Rodolphe > -- > Rodolphe Lepigre > LAMA, Université Savoie Mont Blanc, FRANCE > http://lama.univ-smb.fr/~lepigre/ > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 1897 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Printf.sprintf "%a" 2016-07-08 8:08 ` Nicolas Ojeda Bar @ 2016-07-08 8:16 ` Rodolphe Lepigre 2016-07-08 10:53 ` Gabriel Scherer 0 siblings, 1 reply; 5+ messages in thread From: Rodolphe Lepigre @ 2016-07-08 8:16 UTC (permalink / raw) To: Nicolas Ojeda Bar; +Cc: OCaml Mailing List Thanks for your answer! > I don't think this is possible with Printf. But if you can switch to Format > you can use Format.asprintf instead. Yes, I know it is possible to use Format. This is actually what I am doing currently! However, I am not using any of the formating features, so I'd like to switch to Printf to avoid going from channels to formatters all the time... >> Dear list, >> >> If I define two values >> >> val p : type out_channel -> blop -> unit >> val e : blop >> >> then I can do something like >> >> Printf.printf "%a" p e >> >> but I can't find a way to do something like >> >> Printf.sprintf "%a" p e >> >> which is not well-typed. Is there any trick that I can use to avoid >> changing the type of [p] to [blop -> string]? >> >> Cheers, >> >> Rodolphe Cheers, Rodolphe -- Rodolphe Lepigre LAMA, Université Savoie Mont Blanc, FRANCE http://lama.univ-smb.fr/~lepigre/ On 08/07/2016 10:08, Nicolas Ojeda Bar wrote: ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Printf.sprintf "%a" 2016-07-08 8:16 ` Rodolphe Lepigre @ 2016-07-08 10:53 ` Gabriel Scherer 2016-07-09 7:26 ` Jonathan Protzenko 0 siblings, 1 reply; 5+ messages in thread From: Gabriel Scherer @ 2016-07-08 10:53 UTC (permalink / raw) To: Rodolphe Lepigre; +Cc: Nicolas Ojeda Bar, OCaml Mailing List [-- Attachment #1: Type: text/plain, Size: 1507 bytes --] For non-formatted printing, I find that bprintf (using Buffer.t) is the more composable primitive. On Fri, Jul 8, 2016 at 4:16 AM, Rodolphe Lepigre < rodolphe.lepigre@univ-savoie.fr> wrote: > Thanks for your answer! > > > I don't think this is possible with Printf. But if you can switch to > Format > > you can use Format.asprintf instead. > > Yes, I know it is possible to use Format. This is actually what I am doing > currently! However, I am not using any of the formating features, so I'd > like to switch to Printf to avoid going from channels to formatters all the > time... > > >> Dear list, > >> > >> If I define two values > >> > >> val p : type out_channel -> blop -> unit > >> val e : blop > >> > >> then I can do something like > >> > >> Printf.printf "%a" p e > >> > >> but I can't find a way to do something like > >> > >> Printf.sprintf "%a" p e > >> > >> which is not well-typed. Is there any trick that I can use to avoid > >> changing the type of [p] to [blop -> string]? > >> > >> Cheers, > >> > >> Rodolphe > > Cheers, > > Rodolphe > -- > Rodolphe Lepigre > LAMA, Université Savoie Mont Blanc, FRANCE > http://lama.univ-smb.fr/~lepigre/ > On 08/07/2016 10:08, Nicolas Ojeda Bar wrote: > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 2532 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Printf.sprintf "%a" 2016-07-08 10:53 ` Gabriel Scherer @ 2016-07-09 7:26 ` Jonathan Protzenko 0 siblings, 0 replies; 5+ messages in thread From: Jonathan Protzenko @ 2016-07-09 7:26 UTC (permalink / raw) To: Gabriel Scherer; +Cc: Nicolas Ojeda Bar, OCaml Mailing List, Rodolphe Lepigre [-- Attachment #1: Type: text/plain, Size: 2035 bytes --] Basically what we did for Mezzo. All printers are intended to work with Buffer.t and %a; then, define a bunch of variants of fprintf, iprintf, kprintf, sprintf, eprintf that work with Buffer.t https://github.com/protz/mezzo/blob/master/lib/MzString.ml On 7/8/16 3:53 AM, Gabriel Scherer wrote: > For non-formatted printing, I find that bprintf (using Buffer.t) is > the more composable primitive. > > On Fri, Jul 8, 2016 at 4:16 AM, Rodolphe Lepigre > <rodolphe.lepigre@univ-savoie.fr > <mailto:rodolphe.lepigre@univ-savoie.fr>> wrote: > > Thanks for your answer! > > > I don't think this is possible with Printf. But if you can > switch to Format > > you can use Format.asprintf instead. > > Yes, I know it is possible to use Format. This is actually what I > am doing > currently! However, I am not using any of the formating features, > so I'd > like to switch to Printf to avoid going from channels to > formatters all the > time... > > >> Dear list, > >> > >> If I define two values > >> > >> val p : type out_channel -> blop -> unit > >> val e : blop > >> > >> then I can do something like > >> > >> Printf.printf "%a" p e > >> > >> but I can't find a way to do something like > >> > >> Printf.sprintf "%a" p e > >> > >> which is not well-typed. Is there any trick that I can use to avoid > >> changing the type of [p] to [blop -> string]? > >> > >> Cheers, > >> > >> Rodolphe > > Cheers, > > Rodolphe > -- > Rodolphe Lepigre > LAMA, Université Savoie Mont Blanc, FRANCE > http://lama.univ-smb.fr/~lepigre/ > <http://lama.univ-smb.fr/%7Elepigre/> > On 08/07/2016 10:08, Nicolas Ojeda Bar wrote: > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > [-- Attachment #2: Type: text/html, Size: 4413 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-07-09 7:26 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-07-08 8:01 [Caml-list] Printf.sprintf "%a" Rodolphe Lepigre 2016-07-08 8:08 ` Nicolas Ojeda Bar 2016-07-08 8:16 ` Rodolphe Lepigre 2016-07-08 10:53 ` Gabriel Scherer 2016-07-09 7:26 ` Jonathan Protzenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox