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 IAA13673; Wed, 19 May 2004 08:17:10 +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 IAA14467 for ; Wed, 19 May 2004 08:17:09 +0200 (MET DST) Received: from caged.spacebird.net (caged.spacebird.net [66.92.161.180]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4J6H8EV019804 for ; Wed, 19 May 2004 08:17:08 +0200 Received: from [10.92.1.1] (helo=word) by caged.spacebird.net with smtp (Exim 3.36 #1 (Debian)) id 1BQL6c-0000BG-00; Wed, 19 May 2004 03:03:10 -0400 Message-ID: <004901c43d68$aa348bc0$10015c0a@word> From: "David J. Trombley" To: "caml-list" Cc: Subject: [Caml-list] format4 query Date: Wed, 19 May 2004 02:15:09 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Miltered: at nez-perce with ID 40AAFBE4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; demonstrate:01 sprintf:01 inferred:01 printf:01 val:01 sprintf:01 val:01 messed:01 kprintf:01 stupid:01 inference:01 screws:99 opaque:01 kprintf:01 inference:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = # let q (a : listener) b = let str = sprintf b in a str;; val q : listener -> (string, unit, string) format -> unit = (* 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 : 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