caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alessandro Baretta <alex@baretta.com>
To: Ocaml <caml-list@inria.fr>
Subject: [Caml-list] Functional scanning facilities
Date: Fri, 12 Jul 2002 03:36:14 +0200	[thread overview]
Message-ID: <3D2E328E.5030505@baretta.com> (raw)

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


             reply	other threads:[~2002-07-12  1:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-12  1:36 Alessandro Baretta [this message]
2002-07-12  2:43 ` John Prevost
2002-07-12  7:24   ` Pierre Weis
2002-07-12  7:55     ` Basile STARYNKEVITCH
2002-07-12  7:58     ` John Prevost
2002-07-12  8:25     ` Stefano Zacchiroli
2002-07-12 11:16       ` Pierre Weis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D2E328E.5030505@baretta.com \
    --to=alex@baretta.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).