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 LAA22149; Tue, 30 Sep 2003 11:20:11 +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 LAA00611 for ; Tue, 30 Sep 2003 11:20:09 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8U9K8523447 for ; Tue, 30 Sep 2003 11:20:08 +0200 (MET DST) Received: (qmail 18407 invoked by uid 566); 30 Sep 2003 09:20:06 -0000 Date: Tue, 30 Sep 2003 11:17:32 +0200 From: Michal Moskal To: Pierre Weis Cc: Richard Jones , caml-list@inria.fr Subject: Re: [Caml-list] Printf question Message-ID: <20030930091732.GA5843@roke.freak> Mail-Followup-To: Pierre Weis , Richard Jones , caml-list@inria.fr References: <20030930080357.GA15744@redhat.com> <200309300845.KAA01493@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200309300845.KAA01493@pauillac.inria.fr> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 printf:01 pierre:01 weis:01 pierre:01 weis:01 bug:01 sth:99 dbh:99 sth:99 foo:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, Sep 30, 2003 at 10:45:13AM +0200, Pierre Weis wrote: > > On Tue, Sep 30, 2003 at 12:36:59AM +0200, Pierre Weis wrote: > > > What do you mean by ``not type safe at all'' ? > > > > Well it's not a bug in the compiler. > > > > Here's an example which isn't type safe: > > > > let sth = dbh#prepare "select name from employees where id = %a" in > > sth#execute string_conversion "foo"; > > > > To avoid going over the same ground again, here's my original posting > > in this thread: > > > > http://caml.inria.fr/archives/200309/msg00294.html > > > > Rich. > > I'm sorry to confess I do not understand the example. BTW my fresh Caml > compiler has the same problem :( > > Objective Caml version 3.07 > > # let sth = dbh#prepare "select name from employees where id = %a" in > sth#execute string_conversion "foo"; > ;; > Unbound value dbh > > Could you give us a self contained example that would run into the > current version and exhibit the ``isn't type safe'' property ? The problem isn't that it will crash the executable or something. Richard means SQL-type-safety. The example (well, SQL tables behind it), expects integer argument to "id = %a", but show that you can pass string (with string_conversion function) as argument to "id = %a". Which would result in perfectly valid string (so you consider it type-safe), but this wouldn't be valid SQL (which Richard considers non-type-safe, and you probably consider logic error). There is simple solution: let sth = (fun i s -> dbh#prepare "select name from employees where id = %a and name = %a" int_conversion i string_conversion s) Which would ensure type-safety Richard is talking about, but he would like to be able to write: let sth = dbh#prepare "select name from employees where id = %i and name = %s" and get the same result. And this wouldn't be hard when he could retain magic typing of printf, but own printf implementation (i.e. to hook into processing of %s and %i). -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- 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