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 TAA14302; Thu, 2 May 2002 19:39:04 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA14295 for caml-list@pauillac.inria.fr; Thu, 2 May 2002 19:39:03 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA13382 for ; Thu, 2 May 2002 19:04:29 +0200 (MET DST) Received: from laurelin.dementia.org ([208.167.88.73]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g42H4RD06825 for ; Thu, 2 May 2002 19:04:28 +0200 (MET DST) Received: (from jprevost@localhost) by laurelin.dementia.org (8.11.6/8.11.6) id g42H9tX68538; Thu, 2 May 2002 13:09:55 -0400 (EDT) (envelope-from visigoth@cs.cmu.edu) X-Authentication-Warning: laurelin.dementia.org: jprevost set sender to visigoth@cs.cmu.edu using -f To: =?iso-8859-1?q?J=E9r=F4me?= Marant Cc: caml-list@inria.fr Subject: Re: [Caml-list] printf and scanf References: <20020501180052.GA13445@hell.mine.nu> <20020502102557.A1696@fr.thalesgroup.com> From: John Prevost Date: 02 May 2002 13:09:55 -0400 In-Reply-To: <20020502102557.A1696@fr.thalesgroup.com> Message-ID: <86r8kulbmk.fsf@laurelin.dementia.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "jm" =3D=3D J=E9r=F4me Marant writes: >> Even if you want to do things at runtime, you can compile the >> default string at compile-time, and then you know the type to >> expect. jm> This is true with the current implementation of printf in jm> the Printf module. But this would be wrong if you consider jm> parameter reordering in the C printf (the printf manual page jm> gives enough good explainations). jm> I've been giving the following example for quite long now: jm> languages do not always order words the same way. So, jm> sometimes, you need to reorder parameters in translated jm> strings in order to get a correct syntax in the targeted jm> language. With printf, you can do it this way: jm> fr: " %s %d" =20=20 jm> string -> int jm> de: " %2$s %1$d" jm> int -> string jm> This example shows that if you want a full featured jm> internationalisation, you cannot state that "you know the type jm> you expect" since you will only determine it at run-time. Actually, this is not a counter-example, it's just a place where the current O'Caml format typing rules are insufficient. In this case, there's a simple reason the two types are different: the formats are incompatible. What you want is: fr: " %d %s" de: " %2$s %1$d" in your model, which produces two formats of type int -> string which can be interchanged. If you only "know the type at runtime", it means you have a type error. Just to add to things: if you use a module as a message catalog with combinator formats, argument re-ordering is based on a wrapper function: let fr k s =3D (lit " " $$ int $$ lit " " $$ str) k s let de k s a b =3D (lit " " $$ str $$ lit " " $$ int) k s a b (One of course should do something to make this at least a little cleaner, though. Including one argument to defeat the polymorphism restriction is one thing, but putting two arguments in is more of a pain.) John. ------------------- 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