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.9 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id EACFCBBC4 for ; Mon, 30 Mar 2009 11:09:38 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtsBAM8o0EnUGyoFlGdsb2JhbACWAwEBAQEJCwgJEQOyN4N6Bg X-IronPort-AV: E=Sophos;i="4.38,445,1233529200"; d="scan'208";a="37478306" Received: from smtp5-g21.free.fr ([212.27.42.5]) by mail4-smtp-sop.national.inria.fr with ESMTP; 30 Mar 2009 11:09:38 +0200 Received: from smtp5-g21.free.fr (localhost [127.0.0.1]) by smtp5-g21.free.fr (Postfix) with ESMTP id B0787D4813D; Mon, 30 Mar 2009 11:09:32 +0200 (CEST) Received: from [192.168.17.1] (ivr94-8-88-162-26-239.fbx.proxad.net [88.162.26.239]) by smtp5-g21.free.fr (Postfix) with ESMTP id B6D82D480CF; Mon, 30 Mar 2009 11:09:29 +0200 (CEST) Message-ID: <49D08C9E.4060707@users.sourceforge.net> Date: Mon, 30 Mar 2009 11:10:54 +0200 From: Zheng Li User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b4pre) Gecko/20090328 Lightning/1.0pre Shredder/3.0b3pre MIME-Version: 1.0 To: Anil Madhavapeddy Cc: OCaml Subject: Re: mixing infix functions and the format4 types References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; infix:01 anil:01 infix:01 printf:01 ocaml:01 printf:01 kprintf:01 val:01 foo:01 foo:01 val:01 separators:01 sprintf:01 2009:98 fmt:01 Hello, On 3/30/2009 2:18 AM, Anil Madhavapeddy wrote: > Is there any way to mix infix operators with the Printf format6 types? > I have a code printing module where this would be quite convenient > syntactically, but the obvious attempt didn't work: > > $ ocaml > Objective Caml version 3.11.0 > # open Printf;; > # let myfn m s = let xfn o = m ^ ": " ^ o in kprintf xfn s;; > val myfn : string -> ('a, unit, string, string) format4 -> 'a = > # myfn "foo" "bar";; > - : string = "foo: bar" > # myfn "foo" "%s %s" "bar1" "bar2";; > - : string = "foo: bar1 bar2" > # let (---) m s = myfn m s;; > val ( --- ) : string -> ('a, unit, string, string) format4 -> 'a = > # "foo" --- "bar";;; > - : string = "foo: bar" > # "foo" --- "%s %s" "bar1" "bar2";; > Error: This expression is not a function, it cannot be applied > Is extra separators acceptable? # let ($) f x = f x;; val ( $ ) : ('a -> 'b) -> 'a -> 'b = # "foo" --- "%s %s %s" $ "bar1" $ "bar2" $ "bar3";; - : string = "foo: bar1 bar2 bar3" and, maybe in another way # let (%) fmt x = Printf.sprintf fmt x;; val ( % ) : ('a -> 'b, unit, string) format -> 'a -> 'b = # "%s %s %s" % "bar1" $ "bar2" $ "bar3";; - : string = "bar1 bar2 bar3" HTH. -- Zheng