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 IAA00829; Fri, 16 Jul 2004 08:02:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA00582 for ; Fri, 16 Jul 2004 08:02:29 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6G62SSH011821; Fri, 16 Jul 2004 08:02:28 +0200 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA00723; Fri, 16 Jul 2004 08:02:27 +0200 (MET DST) From: Pierre Weis Message-Id: <200407160602.IAA00723@pauillac.inria.fr> Subject: Re: [Caml-list] kprintf with user formatters In-Reply-To: <20040715093953.53769963@mostha> from Damien at "Jul 15, 104 09:39:53 am" To: Damien.Pous@ens-lyon.fr (Damien) Date: Fri, 16 Jul 2004 08:02:27 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 40F76F74.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pierre:01 weis:01 pierre:01 weis:01 caml-list:01 kprintf:01 formatters:01 fmt:01 printf:01 printf:01 fmt:01 val:01 eats:01 -rectypes:01 'b-:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk [...] > I had the same problem a month ago, > I ended with the following ugly function: > > let log b fmt = > if b then Printf.printf fmt > else > let rec f x = Obj.magic f in > f fmt > (* val f: bool -> ('a, out_channel, unit) format -> 'a *) > > (I think this is safe since f just eats its arguments, > and gets typed with "-rectypes" : ('b->'a) as 'a) No, this is not safe: you break the type system and create buggy values like that. # let log b fmt = if b then Printf.printf fmt else let rec f x = Obj.magic f in f fmt;; val log : bool -> ('a, out_channel, unit) format -> 'a = # log false "";; - : unit = # let x = log false "";; val x : unit = # Marshal.to_string;; - : 'a -> Marshal.extern_flags list -> string = # Marshal.to_string x [];; Exception: Invalid_argument "output_value: abstract value (outside heap)". There is clearly something wrong! > maybe a function "zprintf" could be added to Printf and Format to do > this job ? It is overkill to introduce a new printf function just for that case. I suggest we try a bit harder to find an acceptable solution without introducing zprintf :) Best regards, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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