From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 9036E7F72C for ; Fri, 12 Aug 2016 14:55:26 +0200 (CEST) IronPort-PHdr: 9a23:dt5kLBA+Kq7K10OwYWqQUyQJP3N1i/DPJgcQr6AfoPdwSP/4pMbcNUDSrc9gkEXOFd2CrakV0qyP6+u9BSRAuc/H6yFaNsQUFlcssoY/p0QYGsmLCEn2frbBThcRO4B8bmJj5GyxKkNPGczzNBX4q3y26iMOSF2kbVImbtr8FoOatcmrzef6o8SVOFQRwmPlKu4uZFXu9EOK55FQ2dMjYo8KiTLx6kNSfOpXwW46bXmypD3bovmKwZh47i5LsOgg/cMTGY/zfqA/UKAKRG9+azN9zITRuBLCVQqC4GcHGiVTy0IQQlvz1wzhRpr6rgf9s+N83mHaYZy3HvgIXmGB5qRiRAKg3CQONDc17SfXg8J5iqtdqTquohV+x8jfZ4TDZ9RkeaaIUN8dWGNbUo58SSVHDY64bpATDqJVMOpfsoDnqx0DsxK4CgSoBfjzyxdTgnTrm6Yz1qIoGkfb31pzTJo1rH3IoYCtZ+8pWuevwfyNkGzO Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=edouardevangelisti@gmail.com; spf=Pass smtp.mailfrom=edouardevangelisti@gmail.com; spf=None smtp.helo=postmaster@mail-ua0-f175.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of edouardevangelisti@gmail.com) identity=pra; client-ip=209.85.217.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="edouardevangelisti@gmail.com"; x-sender="edouardevangelisti@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of edouardevangelisti@gmail.com designates 209.85.217.175 as permitted sender) identity=mailfrom; client-ip=209.85.217.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="edouardevangelisti@gmail.com"; x-sender="edouardevangelisti@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ua0-f175.google.com) identity=helo; client-ip=209.85.217.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="edouardevangelisti@gmail.com"; x-sender="postmaster@mail-ua0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BYAAAYxq1Xf6/ZVdFehBt8B6dUBYUjjCiBfiOFeYFCBzgUAQEBAQEBAQERAQEJCwsJFzGCMgQBE4IUAQEEARIRHQEIJQsBAwELAQUFCw0NHQICIQESAQUBChIGExIQh3UDDwgOoQaBMj4yizyERQWGcCcDCisag3sBAQEHAQEBAQEBGQIGEIYahE2CQ4Iqghw4gloFhlsMkiE0gWKEPIY5gj6COY0KiC2ECII4Ex6BDw8PdYM8OzKHKwEBAQ X-IPAS-Result: A0BYAAAYxq1Xf6/ZVdFehBt8B6dUBYUjjCiBfiOFeYFCBzgUAQEBAQEBAQERAQEJCwsJFzGCMgQBE4IUAQEEARIRHQEIJQsBAwELAQUFCw0NHQICIQESAQUBChIGExIQh3UDDwgOoQaBMj4yizyERQWGcCcDCisag3sBAQEHAQEBAQEBGQIGEIYahE2CQ4Iqghw4gloFhlsMkiE0gWKEPIY5gj6COY0KiC2ECII4Ex6BDw8PdYM8OzKHKwEBAQ X-IronPort-AV: E=Sophos;i="5.28,510,1464645600"; d="scan'208,217";a="187515146" Received: from mail-ua0-f175.google.com ([209.85.217.175]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 12 Aug 2016 14:55:25 +0200 Received: by mail-ua0-f175.google.com with SMTP id k90so40309234uak.1 for ; Fri, 12 Aug 2016 05:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=er5v5HHS1xh8YqfjZctzEtbJoEPKYvCa524KfJfWfjs=; b=mWsksn3S4ePW8OJWZeuYBcUQC0XRI0TAXY4npWjFc7Xnqb6K+39q76FP0NBmVMxcxT QBrUlR3veq1wHOuUQ85AP2gXQ2HKMFQLVOmxSoOb4vfm7Yf2KiUdidUAwYk6EKLCIqCo omMLfrbZApxwz5t9nPN2vcbwl4NRcns/sEajsiC5SIL688w0eNn4ICG/tYG7y+5AdlGr pikzi3w2jj0/OMODgxzWmnq4SijGq3V8pVah50tB6yLFdcXOcpAaWdp6ZQCtIxfh4ZR/ oOTswS61KF95DscZNNuFB+EoI3Xpe7kFyT6VvVOnvBZPk0DbiX4rOZQed7ohEWwrJsZw viJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=er5v5HHS1xh8YqfjZctzEtbJoEPKYvCa524KfJfWfjs=; b=je8AGb9eL9RMeZWhZzJIcDsvomPILJGnhA6L6zB1zrhMeEUDqTs9UMfNyGo/rLDhut Be69x4csd/+B7PkXyXd8dTjcE3aGGeJYILeFz5DCg9jRv2ba2sGHb2a6UJd1h2r36RS1 43T+3uYRxecAYlyl3NApuz8wkj8SPOICE0P0c6MvH6C1Q7A1UAquvE/0yabXkM8PWWqx 8my1FTQ6pgU99sHfzRwgwiNok55MOSFRiXt3x9xnADzPk57eHZvk/o/vJKCX9cU+4Syy f/mXztDF9R+Goi6SVTcboN0Rnw7FTfeC2blj0zDrQUW7NA6wb12W4nI6fKl1r7mOxD0S 34Jg== X-Gm-Message-State: AEkoousUhn4lbAx1lBBmvjIPBr2uzjOwKx/gHoGsT0NfjOk1SI8mB6P6eYNeuzsTVOLBmlRrrR8NYblAP5ecdw== X-Received: by 10.31.63.199 with SMTP id m190mr7458603vka.23.1471006524312; Fri, 12 Aug 2016 05:55:24 -0700 (PDT) MIME-Version: 1.0 Sender: edouardevangelisti@gmail.com Received: by 10.176.69.140 with HTTP; Fri, 12 Aug 2016 05:55:09 -0700 (PDT) In-Reply-To: References: <0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46@IRSMSX102.ger.corp.intel.com> From: Edouard Evangelisti Date: Fri, 12 Aug 2016 13:55:09 +0100 X-Google-Sender-Auth: sX7-dbTW3Gn23cGsWpu2S879xEk Message-ID: To: Kakadu Cc: "Soegtrop, Michael" , "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=001a114dbc785810750539df6573 X-Validation-by: edouard.evangelisti@slcu.cam.ac.uk Subject: Re: [Caml-list] Question on Printf wrappers --001a114dbc785810750539df6573 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable You may also consider this: let prefixprint oc fmt =3D Printf.fprintf oc ("Prefix: " ^^ fmt) Best regards, Edouard 2016-08-12 13:51 GMT+01:00 Kakadu : > Micheal, > > Something lke this? > > let printfn fmt =3D kprintf (printf "%s\n") fmt > > Happy hacking, > Kakadu > > On Fri, Aug 12, 2016 at 3:44 PM, Soegtrop, Michael > wrote: > > Dear Ocaml Users, > > > > > > > > it is quite common to have wrappers for printf to e.g. print errors or > > warnings with some context. Prefixing is easy to do in OCaml (honestly = it > > took me a short while to figure it out): > > > > > > > > let prefixprintf (oc : out_channel) (fmt : ('a, out_channel, unit) > format) : > > 'a =3D > > > > Printf.fprintf oc "Prefix: "; > > > > Printf.fprintf oc fmt > > > > ;; > > > > > > > > I wonder how I would postfix something. Even converting the formatted > output > > first to a string and then output it together with the postfix doesn=E2= =80=99t > seem > > to be easy, because the formatting function must be the last call in the > > function, since it has to produce the returned function. Is there some > way > > to make a variadic lambda expression or some other magic to handle such > > cases? A similar question would be how I can print the same formatted > string > > twice. > > > > > > > > I don=E2=80=99t have an application for this, I ask this out of pure OC= aml > > curiosity. So I am not so much interested in workarounds, more in an > answer > > to the question how I can return a function of type =E2=80=98a without = more or > less > > directly calling some variant of printf. > > > > > > > > Best regards, > > > > > > > > Michael > > > > > > > > Intel Deutschland GmbH > > Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany > > Tel: +49 89 99 8853-0, www.intel.de > > Managing Directors: Christin Eisenschmid, Christian Lamprechter > > Chairperson of the Supervisory Board: Nicole Lau > > Registered Office: Munich > > Commercial Register: Amtsgericht Muenchen HRB 186928 > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs --=20 *Edouard Evangelisti* *Post doctoral Research Associate* *Sainsbury Laboratory, Cambridge University (SLCU)* *Bateman StreetCambridge CB2 1LR (United Kingdom)* --001a114dbc785810750539df6573 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
You may also consider this:
let prefixprint oc fmt =3D Printf.fp= rintf oc ("Prefix: " ^^ fmt)

Best regards,
Edouard


2016-08-1= 2 13:51 GMT+01:00 Kakadu <kakadu.hafanana@gmail.com>= :
Micheal,

Something lke this?

let printfn fmt =3D kprintf (printf "%s\n") fmt

Happy hacking,
Kakadu

On Fri, Aug 12, 2016 at 3:44 PM, Soegtrop, Michael
<michael.soegtrop@intel.co= m> wrote:
> Dear Ocaml Users,
>
>
>
> it is quite common to have wrappers for printf to e.g. print errors or=
> warnings with some context. Prefixing is easy to do in OCaml (honestly= it
> took me a short while to figure it out):
>
>
>
> let prefixprintf (oc : out_channel) (fmt : ('a, out_channel, unit)= format) :
> 'a =3D
>
>=C2=A0 =C2=A0Printf.fprintf oc "Prefix: ";
>
>=C2=A0 =C2=A0Printf.fprintf oc fmt
>
> ;;
>
>
>
> I wonder how I would postfix something. Even converting the formatted = output
> first to a string and then output it together with the postfix doesn= =E2=80=99t seem
> to be easy, because the formatting function must be the last call in t= he
> function, since it has to produce the returned function. Is there some= way
> to make a variadic lambda expression or some other magic to handle suc= h
> cases? A similar question would be how I can print the same formatted = string
> twice.
>
>
>
> I don=E2=80=99t have an application for this, I ask this out of pure O= Caml
> curiosity. So I am not so much interested in workarounds, more in an a= nswer
> to the question how I can return a function of type =E2=80=98a without= more or less
> directly calling some variant of printf.
>
>
>
> Best regards,
>
>
>
> Michael
>
>
>
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
> Tel: += 49 89 99 8853-0, www.intel.de
> Managing Directors: Christin Eisenschmid, Christian Lamprechter
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
=
Edouard Evangelisti
=
Post doctoral Research Associate
Sainsbury Laboratory,= Cambridge University (SLCU)
Bateman Street
Cambridge CB2 1LR (United Kingdom)
--001a114dbc785810750539df6573--