caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] is there a way for turning strings to "format"s?
@ 2013-11-06 12:39 Matej Kosik
  2013-11-06 12:44 ` Simon Cruanes
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Matej Kosik @ 2013-11-06 12:39 UTC (permalink / raw)
  To: OCaml

Hi,

I would like to ask, how to do something like:

	let computed_format = Printf.sprintf "%%0%dd" 5 in
	Printf.printf computed_format 42

The above code is rejected, because "computed_format" is of type "string" whereas

        ('a -> 'b, out_channel, unit) format =
           ('a -> 'b, out_channel, unit, unit, unit, unit) format6

type was expected.

My question is: is it possible to turn strings to values that would be accepted by Printf.printf as its first parameter?

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [Caml-list] is there a way for turning strings to "format"s?
@ 2013-11-06 12:54 "Mark Adams"
  2013-11-07  7:33 ` Gabriel Scherer
  0 siblings, 1 reply; 10+ messages in thread
From: "Mark Adams" @ 2013-11-06 12:54 UTC (permalink / raw)
  To: caml-list

There's always the nasty 'Obj.magic' for conversion between arbitrary types:

    let computed_format = Printf.sprintf "%%0%dd" 5 in
    Printf.printf (Obj.magic computed_format) 42

Surely there must be a nicer way of doing this, but I don't know of one.

Mark.

on 6/11/13 12:40 PM, Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
wrote:

> Hi,
>
> I would like to ask, how to do something like:
>
> let computed_format = Printf.sprintf "%%0%dd" 5 in
> Printf.printf computed_format 42
>
> The above code is rejected, because "computed_format" is of type "string"
> whereas
>
> ('a -> 'b, out_channel, unit) format =
> ('a -> 'b, out_channel, unit, unit, unit, unit) format6
>
> type was expected.
>
> My question is: is it possible to turn strings to values that would be
> accepted by Printf.printf as its first parameter?
>
> --
> 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
>
>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-11-07 21:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-06 12:39 [Caml-list] is there a way for turning strings to "format"s? Matej Kosik
2013-11-06 12:44 ` Simon Cruanes
2013-11-06 12:50 ` Robert Jakob
2013-11-06 12:57 ` Jeremy Yallop
2013-11-06 13:08   ` Matej Kosik
2013-11-06 12:54 "Mark Adams"
2013-11-07  7:33 ` Gabriel Scherer
2013-11-07  7:50   ` David MENTRE
2013-11-07 20:45     ` Ollie Frolovs
2013-11-07 21:14       ` Yaron Minsky

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).