From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA27775 for caml-red; Sat, 25 Nov 2000 16:44:13 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA03304 for ; Thu, 23 Nov 2000 16:14:24 +0100 (MET) Received: from sdmmx1.sdm.de (sdmmx1.sdm.de [192.76.162.232]) by nez-perce.inria.fr (8.11.1/8.10.0) with SMTP id eANFENb14329 for ; Thu, 23 Nov 2000 16:14:23 +0100 (MET) Received: FROM muccpu1.muc.sdm.de BY sdmmx1.sdm.de ; Thu Nov 23 16:13:41 2000 0000 Received: by muccpu1.muc.sdm.de (Sendmail 8.9.3+Sun) via ESMTP for from mucexch2.muc.sdm.de id QAA07999; Thu, 23 Nov 2000 16:14:39 +0100 (MET) Received: by mucexch.muc.sdm.de with Internet Mail Service (5.5.2650.21) id ; Thu, 23 Nov 2000 16:13:36 +0100 Message-ID: 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 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" Sender: weis@pauillac.inria.fr 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 = 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