Browse thread
[Caml-list] format type
- Cezary Kaliszyk
[
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: | Cezary Kaliszyk <ck189400@z...> |
| 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.
All works ok for nonempty format.
Ie:
myfun "%c%s"
is of type:
(char -> string -> unit) -> unit
IS IT POSSIBLE (with the current implementation) of the format type type
checking to pass some format that would require a (unit -> unit)
function?
Ie: I'd like:
myfun ""
to be of type:
(unit -> unit) -> unit
If such construnction is not possible at all perheapes some new
identifier "%?" should be added to fromat type type checking. This
argument would take exacly one argument of type unit.
My current implementation:
let receive (fmt : (('a, unit, unit) format)) (f : 'a) : unit =
let fmt_str = string_of_format fmt in
let rec parse f i =
match fmt.[i] with
...
I call recursively:
parse (lazified ((forced f) with applied arg)) (i + 1)
...
in
Obj.magic (parse (fun () -> f) 0) ()
;;
The only known workaround for me for now is to pass "%t" and
make my function not (unit -> unit) but ('a -> unit).
Writing code with changed types just for the sake of the language is
very bad. And with "%t" 'a seems to be (unit -> unit).
Cezary Kaliszyk
--