From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA30056; Tue, 14 Sep 2004 23:56:05 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 XAA30000 for ; Tue, 14 Sep 2004 23:56:03 +0200 (MET DST) Received: from smtp-2.syd.swiftdsl.com.au (smtp-2.syd.swiftdsl.com.au [218.214.224.98]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id i8ELtofk018243 for ; Tue, 14 Sep 2004 23:55:52 +0200 Received: (qmail 24352 invoked from network); 14 Sep 2004 21:55:49 -0000 Received: from unknown (HELO coltrane.mega-nerd.net) (218.214.64.136) by smtp-2.syd.swiftdsl.com.au with SMTP; 14 Sep 2004 21:55:49 -0000 Received: from coltrane (localhost [127.0.0.1]) by coltrane.mega-nerd.net (Postfix) with SMTP id 1984A7AE1 for ; Wed, 15 Sep 2004 07:55:47 +1000 (EST) Date: Wed, 15 Sep 2004 07:55:47 +1000 From: Erik de Castro Lopo To: caml-list@inria.fr Subject: [Caml-list] Passing printf format strings to functions Message-Id: <20040915075547.54c0bef6.ocaml-erikd@mega-nerd.com> Organization: Erik Conspiracy Secret Labs X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; passing:01 printf:01 fmt:01 endline:01 printf:01 fmt:01 sprintf:01 endline:01 rec:01 compile:02 nospam:97 unit:03 unit:03 string:03 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi all, I've got a little problem which I can't seem to get to the bottom of. The following code snippet won't compile: let rec print_string_pairs (fmt:string) = function [] -> print_endline "" | a :: b -> Printf.printf fmt (fst a) (snd a) ; print_string_pairs fmt b ;; let fmt = Printf.sprintf " %%%ds == %%s\n" 20 ;; print_endline fmt ;; let pairs = [ ("a", "b") ; ("c", "d") ; ("e", "f") ] ;; print_string_pairs fmt pairs ;; and it gives me an error (line 5 is the Printf.printf line): File "fmt.ml", line 5, characters 18-21: This expression has type string but is here used with type ('a -> 'b -> 'c, out_channel, unit) format = ('a -> 'b -> 'c, out_channel, unit, unit) format4 If I replace "fmt" on that line with Printf.printf "%s %s\n" (fst a) (snd a) ; there is no problem. I think this is something to do with type inferencing of format strings but I can't get to the bottom of it. Any suggestions? TIA, Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ "Using Java as a general purpose application development language is like going big game hunting armed with Nerf weapons." -- Author Unknown ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners