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 MAA04578; Mon, 4 Nov 2002 12:56:36 +0100 (MET) 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 MAA05008 for ; Mon, 4 Nov 2002 12:56:35 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (host77-68.pool80116.interbusiness.it [80.116.68.77]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gA4BuYD01879 for ; Mon, 4 Nov 2002 12:56:34 +0100 (MET) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 0F82C2724F; Mon, 4 Nov 2002 12:56:10 +0100 (CET) Message-ID: <3DC6605A.6060302@baretta.com> Date: Mon, 04 Nov 2002 12:56:10 +0100 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Cezary Kaliszyk , Ocaml Subject: Re: [Caml-list] format type References: <3DC627A5.9090900@baretta.com> <20021104110359.GA17924@zodiac.mimuw.edu.pl> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Cezary Kaliszyk wrote: > On Mon, Nov 04, 2002 at 08:54:13AM +0100, Alessandro Baretta wrote: > >>>>The only known workaround for me for now is to pass "%t" and >>>>make my function not (unit -> unit) but ('a -> unit). >>> >>As far as I can see from the docs, "%t" is only meaningful >>with the Printf module. I see no mention of it in Scanf. >>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'd avoid "reinventing the wheel" and stick with well known protocols. Did you try anything XML based? It's versatile and well supported. And it will spare you a lot of low level parsing routines. But of course, it is suboptimal, bitrate-wise. > I am writing a function which adds a message to the protocol, which takes the > 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 = 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. I have a feeling you are asking more of the format type than it was meant to handle. The format type is meant to be used with the Scanf and Printf modules. You can parse a message according to a format with Scanf, and by the same means you can format a message with Printf. If you are using format values in different contexts, you are probably abusing them. >>Assuming you are talking about the Scanf module, I'd say you >>can't. Of course, if your function takes a unit input, it >>can very well be a perfectly polymorphic function (? la >>ignore) with type ('a -> unit). In which case you can force >>a call to such function while scanning the input buffer by >>passing it a range conversion with an empty range: >>"%[^\000-\255]". Your function would be called with an empty >>string as an actual parameter. > > I'm not talkin about Printf nor Scanf, but about my module that uses the > format type. > 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 I lost track of what you are trying to do. Sorry for this. But I have a feeling you are making things much more complex than necessary. Did you consider using yacc to parse your data stream according to your protocol specification? Format strings are sad heritage from C, and good for quick hacks where you do not want to take the time to write up a lexer and a parser, but you must realize they have some limitations. I'm sorry for not being any more helpful. Alex ------------------- 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