caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: jim.rauser@sdm.de
To: caml-list@inria.fr
Subject: AW: Format.sprintf and "%a"
Date: Thu, 23 Nov 2000 16:13:35 +0100	[thread overview]
Message-ID: <C9A98ED35114D31197D000805FEA668E02650FA0@mucexch.muc.sdm.de> (raw)

Pierre Weis wrote:
>
> Nothing more than the reported type error: your functions  are
> designed to return unit (they work by side effect) not string (which
> would mean they are functional), and this is obviously uncompatible.
>
> let s =
>  Format.fprintf str_formatter "Test: %a@." fmt_foo Foo;
>  Format.flush_str_formatter ();;
> val s : string = "Test: Foo\n"

Okay, I found the definition of the type "format" in pervasives.mli,
so I understand the type error now.  But I then tried to partially
apply Format.fprintf to Format.str_formatter:

  let fsprintf = Format.fprintf Format.str_formatter;;
  val fsprintf : ('_a, Format.formatter, unit) format -> '_a = <fun>

Looks good, except for the ominous "_" in front of the type variable
(what does it mean, anyway?).  But:

  let fmt_string f s = Format.fprintf f "%s" s;;
  fsprintf "%a@." fmt_string "foo";;
                  ----------
  This expression has type Format.formatter -> string -> unit
  but is here used with type (string -> 'a, Format.formatter, unit) format

This type error also makes sense.  What I don't understand is,
why it *does* work with Format.fprintf, that is, how the compiler
convinces itself that an argument list like ["%a" fmt_string "foo"]
unifies with the type [('a, Format.formatter, unit) format]?  I don't
recall seeing anything else in the manual that talks about functions
with variable arity; is there some extra-linguistic magic going on here?

Thanks again,

Jim

------------------------------------------------------------------------
Jim Rauser                                      mailto:rauser@qcentic.de
Qcentic GmbH
Max-Planck-Str. 39a                                 Tel: 02234/950 36 16
D-50858 Koeln                                        Fax: 02234/27 19 17



             reply	other threads:[~2000-11-25 15:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-23 15:13 jim.rauser [this message]
2000-11-25 15:43 ` Pierre Weis
2000-11-28 12:52 ` thierry BRAVIER

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=C9A98ED35114D31197D000805FEA668E02650FA0@mucexch.muc.sdm.de \
    --to=jim.rauser@sdm.de \
    --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).