Browse thread
[Caml-list] Functional scanning facilities
- Alessandro Baretta
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alessandro Baretta <alex@b...> |
| Subject: | [Caml-list] Functional scanning facilities |
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