From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 66DD0BBC1 for ; Wed, 23 Apr 2008 22:42:47 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AogAADM8D0hCm3xrnWdsb2JhbACRUgEBAQEBCA0HnCs X-IronPort-AV: E=Sophos;i="4.25,701,1199660400"; d="scan'208";a="11351780" Received: from www.janestcapital.com (HELO smtp.janestcapital.com) ([66.155.124.107]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Apr 2008 22:42:46 +0200 Received: from [172.25.129.161] [38.105.200.250] by janestcapital.com with ESMTP (SMTPD-9.10) id AF450330; Wed, 23 Apr 2008 16:42:45 -0400 Message-ID: <480F9F45.4040101@janestcapital.com> Date: Wed, 23 Apr 2008 16:42:45 -0400 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: ifprint and format type question Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; foo:01 printf:01 printf:01 foo:01 unify:01 fmt:01 fmt:01 strings:01 strings:01 output:02 output:02 string:02 string:02 unit:03 unit:03 So, I'm trying to write code like (simplifying): let my_output (_: string) = ();; (* the real code is much more complicated but not relevant *) let foo b fmt = if not b then Printf.ifprintf () fmt else Printf.ksprintf my_output fmt ;; The problem is that the above code doesn't compile- ifprintf wants fmt to be ('b, unit, unit) format = ('b, unit, unit, unit) format4, while ksprintf wants it to be ('b, unit, string, 'a) format4. Now, I could do the above like: let foo b fmt = Printf.ksprintf (fun s -> if b then my_output s) fmt but the point and purpose of using ifprintf is to avoid the cost of converting the arguments to strings that are just going to be thrown away. So, my questions are: 1: is there a way to make this work without using Obj.magic or rewritting isprintf? 2: is there a reason ifprintf has the type 'a -> ('b, 'a, unit) format -> 'b, instead of ('b, 'a, 'c) format -> 'b, or better yet ('b, 'a, 'c, 'd) format4 -> 'b, or even better yet ('b, 'a, 'c, 'd, 'e, 'f) format6 -> 'b (allowing it to unify with more different formats)? 3: Does ifprintf actually avoid the cost of converting it's arguments to strings? The code is unclear. If the answer to this is 'no', the other two questions are moot. Brian