caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <visigoth@cs.cmu.edu>
To: "Jérôme Marant" <jerome.marant@free.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] printf and scanf
Date: 02 May 2002 13:09:55 -0400	[thread overview]
Message-ID: <86r8kulbmk.fsf@laurelin.dementia.org> (raw)
In-Reply-To: <20020502102557.A1696@fr.thalesgroup.com>

>>>>> "jm" == Jérôme Marant <jerome.marant@free.fr> 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"
  
    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     = (lit " " $$ int $$ lit " " $$ str) k s
let de k s a b = (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


  parent reply	other threads:[~2002-05-02 17:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-01 18:00 Francois-Rene Rideau
2002-05-02  8:25 ` Jérôme Marant
2002-05-02 16:11   ` Pixel
2002-05-02 17:50     ` Jérôme Marant
2002-05-02 17:09   ` John Prevost [this message]
2002-05-02 17:52     ` Jérôme Marant
  -- strict thread matches above, loose matches on Subject: below --
2002-04-30 13:51 Francois-Rene Rideau
2002-05-01 16:06 ` Jérôme Marant
2002-05-02  6:55 ` Francois Pottier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86r8kulbmk.fsf@laurelin.dementia.org \
    --to=visigoth@cs.cmu.edu \
    --cc=caml-list@inria.fr \
    --cc=jerome.marant@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).