Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* AW: Format.sprintf and "%a"
@ 2000-11-23 15:13 jim.rauser
  2000-11-25 15:43 ` Pierre Weis
  2000-11-28 12:52 ` thierry BRAVIER
  0 siblings, 2 replies; 3+ messages in thread
From: jim.rauser @ 2000-11-23 15:13 UTC (permalink / raw)
  To: caml-list

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



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

end of thread, other threads:[~2000-11-28 21:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-23 15:13 AW: Format.sprintf and "%a" jim.rauser
2000-11-25 15:43 ` Pierre Weis
2000-11-28 12:52 ` thierry BRAVIER

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox