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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 8C9EE7F72A for ; Fri, 12 Aug 2016 14:45:18 +0200 (CEST) IronPort-PHdr: 9a23:GjaTbhVEaWYwmslzGVNHmeErTpbV8LGtZVwlr6E/grcLSJyIuqrYZh2Gt8tkgFKBZ4jH8fUM07OQ6PG5HzVYqsvd+DBaKdoXBkdD0Z1X1yUbQ+e9QXXhK/DrayFoVO9jb3RCu0+BDE5OBczlbEfTqHDhpRQbGxH4KBYnbr+tQt2asc272qiI9oHJZE0Q3XzmMOo0dU398FmZ9pFPx9AzcuBpklqBi0ALUtwe/XlvK1OXkkS0zeaL17knzR5tvek8/dVLS6TwcvdwZ7VZCDM7LzJ9v5Wz5lGQBTeIszEXW2AS1x5JGBTt7RfgX563vDGw/r520SyeeMn3VqwcWDK47q4tRgW+2wkdMDtsulrQh8NslqVD5FqEphd/yoPQKsnBMft1fqrQeZUBQmdOQtxWTwRABJ+xa80ECO9XbrUQlJX0u1Zb9Uj2PgKrHu66kjI= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=michael.soegtrop@intel.com; spf=Pass smtp.mailfrom=michael.soegtrop@intel.com; spf=None smtp.helo=postmaster@mga02.intel.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of michael.soegtrop@intel.com) identity=pra; client-ip=134.134.136.20; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="michael.soegtrop@intel.com"; x-sender="michael.soegtrop@intel.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of michael.soegtrop@intel.com designates 134.134.136.20 as permitted sender) identity=mailfrom; client-ip=134.134.136.20; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="michael.soegtrop@intel.com"; x-sender="michael.soegtrop@intel.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mga02.intel.com) identity=helo; client-ip=134.134.136.20; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="michael.soegtrop@intel.com"; x-sender="postmaster@mga02.intel.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BKAABxxK1XhxSIhoZegneBJHwHuSSBfRyGAQKBRjgUAQEBAQEBAQERAQEBCA0JCRkkC4IyFoIdLRxCASpWJgEEG4goAZ8aoBMxhiuJDoJHC1iCLwWZNgYBgTadIZAtHoJZgVduhiwBfgEBAQ X-IPAS-Result: A0BKAABxxK1XhxSIhoZegneBJHwHuSSBfRyGAQKBRjgUAQEBAQEBAQERAQEBCA0JCRkkC4IyFoIdLRxCASpWJgEEG4goAZ8aoBMxhiuJDoJHC1iCLwWZNgYBgTadIZAtHoJZgVduhiwBfgEBAQ X-IronPort-AV: E=Sophos;i="5.28,510,1464645600"; d="scan'208,217";a="229719925" Received: from mga02.intel.com ([134.134.136.20]) by mail2-smtp-roc.national.inria.fr with ESMTP; 12 Aug 2016 14:44:58 +0200 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 12 Aug 2016 05:44:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,510,1464678000"; d="scan'208,217";a="1024321092" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by fmsmga001.fm.intel.com with ESMTP; 12 Aug 2016 05:44:52 -0700 Received: from irsmsx155.ger.corp.intel.com (163.33.192.3) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 12 Aug 2016 13:44:52 +0100 Received: from irsmsx102.ger.corp.intel.com ([169.254.2.123]) by irsmsx155.ger.corp.intel.com ([169.254.14.102]) with mapi id 14.03.0248.002; Fri, 12 Aug 2016 13:44:51 +0100 From: "Soegtrop, Michael" To: "caml-list@inria.fr" Thread-Topic: Question on Printf wrappers Thread-Index: AdH0l01IvSMDpNQZT8yESNvQDM/iLg== Date: Fri, 12 Aug 2016 12:44:51 +0000 Message-ID: <0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46@IRSMSX102.ger.corp.intel.com> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.180] Content-Type: multipart/alternative; boundary="_000_0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46IRSMSX102gercor_" MIME-Version: 1.0 Subject: [Caml-list] Question on Printf wrappers --_000_0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46IRSMSX102gercor_ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Dear Ocaml Users, it is quite common to have wrappers for printf to e.g. print errors or warn= ings 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 outpu= t first to a string and then output it together with the postfix doesn't se= em 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 ca= ses? A similar question would be how I can print the same formatted string = twice. I don't have an application for this, I ask this out of pure OCaml curiosit= y. So I am not so much interested in workarounds, more in an answer to the = question how I can return a function of type 'a without more or less direct= ly 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 --_000_0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46IRSMSX102gercor_ Content-Type: text/html; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable

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 O= Caml (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: ";<= /o:p>

  Printf.fprintf oc fmt

;;

 

I wonder how I would postfix something. Even convert= ing the formatted output first to a string and then output it together with= the postfix doesn’t 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 sim= ilar question would be how I can print the same formatted string twice.

 

I don’t have an application for this, I ask th= is out of pure OCaml curiosity. So I am not so much interested in workaroun= ds, more in an answer to the question how I can return a function of type &= #8216;a 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

--_000_0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46IRSMSX102gercor_--