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 JAA31457; Tue, 5 Nov 2002 09:55:55 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA32477 for caml-list@pauillac.inria.fr; Tue, 5 Nov 2002 09:55:55 +0100 (MET) 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 MAA02955 for ; Mon, 4 Nov 2002 12:04:02 +0100 (MET) Received: from students.mimuw.edu.pl (zodiac.mimuw.edu.pl [193.0.96.128]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gA4B41525123 for ; Mon, 4 Nov 2002 12:04:01 +0100 (MET) Received: by students.mimuw.edu.pl (Postfix, from userid 2733) id 08095179F6; Mon, 4 Nov 2002 12:03:59 +0100 (CET) Date: Mon, 4 Nov 2002 12:03:59 +0100 From: Cezary Kaliszyk To: Alessandro Baretta , caml-list@inria.fr Subject: Re: [Caml-list] format type Message-ID: <20021104110359.GA17924@zodiac.mimuw.edu.pl> References: <3DC627A5.9090900@baretta.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="k+w/mQv8wyuph6w0" Content-Disposition: inline In-Reply-To: <3DC627A5.9090900@baretta.com> User-Agent: Mutt/1.3.27i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --k+w/mQv8wyuph6w0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 04, 2002 at 08:54:13AM +0100, Alessandro Baretta wrote: > >>From: Cezary Kaliszyk > >>Date: Sun, 3 Nov 2002 08:08:58 +0100 > >>To: caml-list@inria.fr > >>Subject: [Caml-list] format type > >> > >>I'm trying to write a function that takes a format and a function and > >>applies some (got from elsewere) arguments to the function. > >> > >> > >> > >>The only known workaround for me for now is to pass "%t" and > >>make my function not (unit -> unit) but ('a -> unit). >=20 > As far as I can see from the docs, "%t" is only meaningful=20 > with the Printf module. I see no mention of it in Scanf.=20 > What exactly are you trying to do anyway? I am trying to create a protocol for passing messages via network. Each message may be acompanied by a certain amount of parameters (of type char, int, float or string) (the parameters are dependant on the message). output/input_value aren't apropriate. (For network speed reasons, and no type extensibility) I am writing a function which adds a message to the protocol, which takes t= he type of arguments accompanying the message and the receiving function. It should return function used to send this message type. Eg: let two_char_sender =3D add_to_protocol "%c%c" two_char_receiver;; Where two_char_receiver : (char -> char -> unit) And tho_char_sender : (char -> char -> unit). And I'd like the types to be controlled. And I've written it. But it doesn't work if I want to create a message that does not take any parameters. And I suppose the builtin type format doesn't have the functionality necessary to write it.=20 > Assuming you are talking about the Scanf module, I'd say you=20 > can't. Of course, if your function takes a unit input, it=20 > can very well be a perfectly polymorphic function (? la=20 > ignore) with type ('a -> unit). In which case you can force=20 > a call to such function while scanning the input buffer by=20 > passing it a range conversion with an empty range:=20 > "%[^\000-\255]". Your function would be called with an empty=20 > string as an actual parameter. I'm not talkin about Printf nor Scanf, but about my module that uses the format type. > Or, better yet, you can use the "%N" conversion, which=20 > passes the number of characters consumed. Just discard this=20 > value. As above. > >>Writing code with changed types just for the sake of the language is > >>very bad. And with "%t" 'a seems to be (unit -> unit). >=20 > It is also very bad to complain without doing any work=20 > yourself. You are probably the only one on this list wishing=20 > to call a function with no input while parsing a buffer.=20 I'm not parsing a buffer... > Nothing wrong with this, apart from stylistic=20 > considerations, but it implies two things: 1) I don't=20 > suppose Pierre ever even thought of such a conversion for=20 > Scanf, and 2) even if he did, I doubt he'd care to implement=20 > it. If you really think it is necessary, you might consider=20 > hacking it into the Scanf module and submitting the patch to=20 > the maintainers. It's not scanf relative... > Alex The format argument is parsed by me, not by scanf or printf (as I wrote in the example code) and I don't know where in ocaml code is type checking of the arguments accompanying the format type. Cezary Kaliszyk --=20 --k+w/mQv8wyuph6w0 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Dalsze informacje znajdują się na http://www.gnupg.org/ iD8DBQE9xlQfYfPl1pqp6/URAo5LAJ92WXoKIkW1cwRjdhZjv2QLU2hXiwCguvxk hTokhcbmLeXlbrbxFhDSvBI= =1DFK -----END PGP SIGNATURE----- --k+w/mQv8wyuph6w0-- ------------------- 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