caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Weis <pierre.weis@inria.fr>
To: rich@annexia.org (Richard Jones)
Cc: pierre.weis@inria.fr, caml-list@inria.fr
Subject: Re: [Caml-list] Printf question
Date: Mon, 29 Sep 2003 21:57:19 +0200 (MET DST)	[thread overview]
Message-ID: <200309291957.VAA09271@pauillac.inria.fr> (raw)
In-Reply-To: <20030929181332.GA10941@redhat.com> from Richard Jones at "Sep 29, 103 07:13:33 pm"

> On Mon, Sep 29, 2003 at 06:42:09PM +0200, Pierre Weis wrote:
> > I'm pretty sure that format string contsnats are typechecked
> > statically with the usual typechecker resolution mechanism (a bit more
> > complex, but no more magic than the typechecking of the -> type
> > constructor).
> > 
> > So why not using format values directly ?
> > 
> > For instance:
> > 
> > # let prepare fmt = Printf.printf fmt;;
> > val prepare : ('a, out_channel, unit) format -> 'a = <fun>
> > 
> > # let sth x =
> >     prepare "select salary from emp where id = %d and name = %s" x;;
> > val sth : int -> string -> unit = <fun>
> > 
> > # sth 1 "Jones"
> > select salary from emp where id = 1 and name = Jones- : unit = ()
> > 
> > This is fully statically typechecked as required.
> > 
> > Or may be I'm missing something ?
> 
> I guess the problem is that I want my own interpretation for
> %s. It has to do SQL-quoting, otherwise you could write:

Hence, I think you are seeking for the %a conversion. For instance,
defining a quotation function for SQL as in

# let sql_quoting oc = Printf.fprintf oc "'%s'";;   
val sql_quoting : out_channel -> string -> unit = <fun>

You can define sth with a %a conversion to apply quoting on the fly:

# let sth x =
    prepare "select salary from emp where id = %d and name = %a" x;;
val sth : int -> (out_channel -> 'a -> unit) -> 'a -> unit = <fun>

# sth 1 sql_quoting "Jones";;
select salary from emp where id = 1 and name = 'Jones'- : unit = ()

Still fully type-checked! Sounds better, no ?

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


-------------------
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


  reply	other threads:[~2003-09-29 19:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-26 18:02 Richard Jones
2003-09-26 19:04 ` Alain.Frisch
2003-09-29  7:44   ` Mike Potanin
2003-09-27  0:11 ` Olivier Andrieu
2003-09-27  7:23   ` Richard Jones
2003-09-27  8:20     ` Basile Starynkevitch
2003-09-27  9:14       ` Richard Jones
2003-09-27  9:39         ` Maxence Guesdon
2003-09-29 16:42         ` Pierre Weis
2003-09-29 18:13           ` Richard Jones
2003-09-29 19:57             ` Pierre Weis [this message]
2003-09-29 21:50               ` Richard Jones
2003-09-29 22:36                 ` Pierre Weis
2003-09-30  8:03                   ` Richard Jones
2003-09-30  8:45                     ` Pierre Weis
2003-09-30  9:17                       ` Michal Moskal
2003-09-30 14:14                         ` Christophe TROESTLER
2003-09-30 13:19                   ` skaller
2003-09-30 20:52                     ` Pierre Weis
2003-10-01 14:39                       ` Christophe TROESTLER
2003-10-01 14:57                         ` Richard Jones
2003-10-01 15:52                           ` [Caml-list] DBI (was: Printf question) Christophe TROESTLER
2003-10-01 16:21                         ` [Caml-list] Printf question Florian Hars
  -- strict thread matches above, loose matches on Subject: below --
2003-05-18  1:34 Brian Hurt
2003-05-18  3:23 ` Manos Renieris
2003-05-18  3:32 ` William Lovas
2003-05-18  6:06 ` Basile STARYNKEVITCH
2003-05-19  9:39   ` Damien

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=200309291957.VAA09271@pauillac.inria.fr \
    --to=pierre.weis@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /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).