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 VAA16594; Mon, 29 Sep 2003 21:57:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 VAA15798 for ; Mon, 29 Sep 2003 21:57:51 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8TJvJH29995; Mon, 29 Sep 2003 21:57:19 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA09271; Mon, 29 Sep 2003 21:57:19 +0200 (MET DST) From: Pierre Weis Message-Id: <200309291957.VAA09271@pauillac.inria.fr> Subject: Re: [Caml-list] Printf question In-Reply-To: <20030929181332.GA10941@redhat.com> from Richard Jones at "Sep 29, 103 07:13:33 pm" To: rich@annexia.org (Richard Jones) Date: Mon, 29 Sep 2003 21:57:19 +0200 (MET DST) Cc: pierre.weis@inria.fr, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] 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; pierre:01 weis:01 pierre:01 weis:01 caml-list:01 printf:01 typechecked:01 statically:01 fmt:01 printf:01 fmt:01 val:01 sth:99 salary:01 emp:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > 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 = > > > > # let sth x = > > prepare "select salary from emp where id = %d and name = %s" x;; > > val sth : int -> string -> unit = > > > > # 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 = 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 = # 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