From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 65245BC69 for ; Mon, 30 Oct 2006 14:28:03 +0100 (CET) Received: from mx1.polytechnique.org (mx1.polytechnique.org [129.104.30.34]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9UDS2ao009286 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 30 Oct 2006 14:28:03 +0100 Received: from localhost (is005115.intra.cea.fr [132.166.135.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTP id 5E6B333210 for ; Mon, 30 Oct 2006 14:28:02 +0100 (CET) Date: Mon, 30 Oct 2006 14:28:01 +0100 From: Virgile Prevosto To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] class and printf Message-ID: <20061030142801.61a936c1@localhost> In-Reply-To: References: <20061030124223.GA46814@ermine.home> X-Mailer: Sylpheed-Claws 2.5.0-rc3 (GTK+ 2.10.6; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-AV-Checked: ClamAV using ClamSMTP at djali.polytechnique.org (Mon Oct 30 14:28:02 2006 +0100 (CET)) X-DCC-xorg-Metrics: djali 32702; Body=1 Fuz1=1 Fuz2=1 X-Org-Mail: virgile.prevosto.1996@polytechnique.org X-Miltered: at discorde with ID 4545FDE2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; printf:01 foo:01 myprintf:01 printf:01 fprintf:01 foo:01 myprintf:01 fmt:01 fprintf:01 fmt:01 stdout:01 val:01 stdout:01 val:01 drink:98 Hello, Le lun 30 oct 2006 14:47:06 CET, "Nicolas Pouillard" a =C3=A9crit : > On 10/30/06, Anastasia Gornostaeva wrote: > > Hello. > > > > What I need to drink to compile it? > > > > class foo ch =3D > > object > > method myprintf =3D Printf.fprintf ch > > end > This one works: >=20 > class ['a] foo ch =3D > object > method myprintf (fmt : ('a, out_channel, unit) format) =3D > Printf.fprintf ch fmt > end >=20 While this solution compiles fine, there might an issue with it, depending on the context where it is to be used: an instance of foo won't be really polymorphic, so that you'll have to use it with=20 the same kind of format string everywhere (from another point of view, it means that you must define an instance for "%s", one for "%d", etc.): # let bar =3D new foo stdout;; val bar : '_a foo =3D # bar#myprintf "foo\n" (* fixes the kind of format string bar can handle *);; * foo - : unit =3D () # bar#myprintf "%s" "foo";; Characters 0-12: bar#myprintf "%s" "foo";; ^^^^^^^^^^^^ This function is applied to too many arguments, maybe you forgot a `;' # bar;; (* check that '_a has been unified with unit *) - : unit foo =3D Maybe a polymorphic method would be better here: class foo ch =3D object method myprintf : 'a.('a, out_channel, unit) format -> 'a =3D fun fmt -> Printf.fprintf ch fmt end ;; class foo : out_channel -> object method myprintf : ('a, out_channel, unit) format -> 'a end # let bar =3D new foo stdout;; val bar : foo =3D # bar#myprintf "foo\n";; foo - : unit =3D () # bar#myprintf "%s" "foo";; foo- : unit =3D () --=20 E tutto per oggi, a la prossima volta. Virgile