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 DAA12503; Fri, 12 Jul 2002 03:29:27 +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 DAA12495 for ; Fri, 12 Jul 2002 03:29:26 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a109.tin.it [62.211.4.109]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6C1TP515522 for ; Fri, 12 Jul 2002 03:29:25 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 08D742739C for ; Fri, 12 Jul 2002 03:36:15 +0200 (CEST) Message-ID: <3D2E328E.5030505@baretta.com> Date: Fri, 12 Jul 2002 03:36:14 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml Subject: [Caml-list] Functional scanning facilities Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk How about something like the follwing--the idea coming from posts I read a while ago about CPS programming: module Scan : sig (* type 'a set *) type ('a, 'b) conversion = ( 'b -> 'a ) -> 'a (* the following signatures refer to stdin scanners *) val s : (string -> 'a) -> 'a val d : (int -> 'a) -> 'a val i : (int -> 'a) -> 'a val o : (int -> 'a) -> 'a val x : (int -> 'a) -> 'a val f : (float -> 'a) -> 'a val c : int -> (string -> 'a) -> 'a (* val set: char set -> (string -> 'a) -> 'a *) type ('a, 'b) scanner = ( 'b -> 'a ) -> ('a, 'c) scanner val nil : (unit, unit) scanner val (+) : 'a scanner -> ('a, 'b) conversion -> 'a scanner val get : ('a, 'b) scanner -> 'a list end Basically, a scanner is a fifo of conversions. Scanners are built by +ing a scanner (left operand) and a conversion (right operand). The fifo must be initialized with a nil scanner, containing no conversions. After a scanner has been built, it must be applied self-recursively to a succession of parameters, each representing a callback for a conversion in the fifo of the scanner. Because a scanner has a recursive type, the result of its application to a callback is a scanner with one less convertions in its fifo. As the convertions are performed, each the result of each callback is appended to a list maintained internally by the scanner. Finally, when all conversions have been performed, the 'a list built by the scanner can be gotten with the get function. Of course, all this works in my best dreams. The scanner type cannot be defined as I have because of the unbound type parameter 'c. But there are work arounds, although not terribly elegant. For example, we could define a big variant type callback_parameter = String of string | Int of int | Float of float | ... but this would greatly reduce the beauty of such a solution. At 3:36 in the morning I can do no better than this. Pierre, Xavier, your turn. 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