caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "\"Mark Adams\"" <mark@proof-technologies.com>
To: <caml-list@inria.fr>
Subject: Re: [Caml-list] is there a way for turning strings to "format"s?
Date: Wed, 06 Nov 2013 12:54:40 +0000	[thread overview]
Message-ID: <1383742480351@names.co.uk> (raw)

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

             reply	other threads:[~2013-11-06 12:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-06 12:54 "Mark Adams" [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2013-11-06 12:39 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1383742480351@names.co.uk \
    --to=mark@proof-technologies.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).