From: "David J. Trombley" <swampy@spacebird.net>
To: "caml-list" <caml-list@inria.fr>
Cc: <hmaon@bumba.net>
Subject: [Caml-list] format4 query
Date: Wed, 19 May 2004 02:15:09 -0400 [thread overview]
Message-ID: <004901c43d68$aa348bc0$10015c0a@word> (raw)
Suppose I have
type listener = string -> unit
which is intended to receive a string type as a value.
Could someone demonstrate a function that takes a listener
and a format as arguments, and uses sprintf to obtain a
string, and then calls the listener with the string
argument? No matter how I seem to do this, the first
parameter of the format4 type seems to get inferred to
string, causing the parser to not consume all of the
intended format tokens, causing a 'too many arguments'
error. For example:
# type listener = string -> unit;;
type listener = string -> unit
# let r s = printf "%s\n" s;;
val r : string -> unit = <fun>
# let q (a : listener) b = let str = sprintf b in a str;;
val q : listener -> (string, unit, string) format -> unit =
<fun>
(* already messed up as evidenced by the first 'string' *)
# q r "%s ya" "hey";;
This function is applied to too many arguments, maybe you
forgot a `;'
I've discovered the kprintf function, which looked promising
since I could get simple examples to work, but utterly fails
in the same stupid way when I put it in a context that is
not a toplevel evaluation. (ie. I try to use this in some
functional way, and the type inference screws up).
Isn't there some way to simply define a function that takes
a format4 arg in some opaque way so that the type of the
result of the kprintf doesn't mess up the type of the
original function by some complicated inference mechanism?
My actual code currently looks something like this:
Hashtbl.iter ( function cbx ->
function
x when x.minLevel <= level ->
(try (Hashtbl.find x.catchExnTable error) error
with Not_found -> let ccb = x.callback stream
level error in
Printf.kprintf ccb
fmt)
| x -> ()
) stream.listeners;
and the types are
val stream : log_stream
val level : log_level
val error : log_error
val fmt : <some sort of format4 that is broken>
type log_callback = (log_stream -> log_level -> log_error ->
string -> unit)
and log_stream = { streamName : string;
listeners : (log_callback, log_entry)
Hashtbl.t }
and log_entry = { callback : log_callback;
minLevel : log_level;
expectList : (int * log_error) list;
catchExnTable : (log_error,
log_error -> unit) Hashtbl.t }
Thanks,
David J. Trombley
-------------------
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
next reply other threads:[~2004-05-19 6:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-19 6:15 David J. Trombley [this message]
2004-05-19 7:22 ` Olivier Andrieu
2004-05-19 16:13 ` David J. Trombley
2004-05-19 17:20 ` Damien Doligez
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='004901c43d68$aa348bc0$10015c0a@word' \
--to=swampy@spacebird.net \
--cc=caml-list@inria.fr \
--cc=hmaon@bumba.net \
/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