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 BAA22702; Fri, 26 Apr 2002 01:33:19 +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 BAA22716 for ; Fri, 26 Apr 2002 01:33:18 +0200 (MET DST) Received: from favie.faith.gr.jp (favie.faith.gr.jp [61.127.175.250]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3PNXFr21160 for ; Fri, 26 Apr 2002 01:33:16 +0200 (MET DST) Received: from localhost (dhcp7.faith.gr.jp [192.168.1.17]) by favie.faith.gr.jp (8.9.3/8.9.3) with ESMTP id IAA21197; Fri, 26 Apr 2002 08:33:09 +0900 To: checker@d6.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to read three integers from a text-file... ? In-Reply-To: <4.3.2.7.2.20020425105510.02d0a600@mail.d6.com> References: <20020425111905.GA31096@kiefer.ai.univie.ac.at> <20020425133343.A31232@fr.thalesgroup.com> <4.3.2.7.2.20020425105510.02d0a600@mail.d6.com> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020426083244K.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 26 Apr 2002 08:32:44 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Chris Hecker > > > Well, this would make a static printf rather that the well known printf > > from C, since the format string may be known only at runtime in some > > cases. > > As Markus says, the Printf.printf doesn't work in this case anyway right > now, since it happens completely at compile time, I believe. Type-checking is completely at compile time, but you can define your format independently if you want: # let fmt : (_,_,_) format = "Hello %s, it's %d:%d.\n";; val fmt : (string -> int -> int -> 'a, 'b, 'a) format = # Printf.printf fmt "Chris" 9 30;; Hello Chris, it's 9:30. Of course this could be done in camlp4 also. The only advantage of the current approach is that the internal representation of the format is still a string, which is kind of memory-efficient. Exercise to the interested reader: Define a function which, given a string and a concrete representation of its format type, checks whether the string conforms to the type. To make it more useful, the concrete representation used should include the format type in its type, using phantom types. val check_format : ('a, 'b) format_type -> string -> bool val make_format : ('a, 'b) format_type -> string -> ('a, 'c, 'b) format # make_format (arr string (arr int (arr int null))) "Hello %s, it's %d:%d.\n";; val fmt : (string -> int -> int -> 'a, 'b, 'a) format = Cheers, Jacques Garrigue ------------------- 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