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 DACE0800B6 for ; Wed, 4 Jan 2017 16:20:08 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=alain.frisch@lexifi.com; spf=None smtp.mailfrom=alain.frisch@lexifi.com; spf=None smtp.helo=postmaster@vrout30.yaziba.net Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain.frisch@lexifi.com) identity=pra; client-ip=185.56.204.35; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain.frisch@lexifi.com"; x-sender="alain.frisch@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain.frisch@lexifi.com) identity=mailfrom; client-ip=185.56.204.35; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain.frisch@lexifi.com"; x-sender="alain.frisch@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@vrout30.yaziba.net) identity=helo; client-ip=185.56.204.35; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain.frisch@lexifi.com"; x-sender="postmaster@vrout30.yaziba.net"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AszC/PxY3U7a6S8WV24CrxhH/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZrsW5bnLW6fgltlLVR4KTs6sC0LuK9fm9EjNcqb+681k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRo?= =?us-ascii?q?LerpBIHSk9631+ev8JHPfglEnjSwbLd9IRmssAnctsYajIltJ60s1hbHv3xEdv?= =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1hbyB2zq0EYNOa2BdD1CMDW/od4KZW/cQO2quJZpPiDUC?= =?us-ascii?q?2r+gULgZ0g2ytQLgg+5pNOPS8SoZrtT708Rp5uDJvRA07z19ScqHhSXFUGF1gm?= =?us-ascii?q?4RWjYs34hgoU1hx06e2LJ7xftCGpgb7PpMVk8nLpPG1KQuANn3XkfFf8yVYFeg?= =?us-ascii?q?WNSvRz8rGIEf2dgLNm95EtSkxj7Z3jGhA/dBnriCBZpy/LjdxHPxD8Jw23fI1e?= =?us-ascii?q?8qiFxwEZgHDnGvmqMqr1ubPIXOiUjM0v/yLak=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AUAACJEW1YhyPMOLldFgYBAQQBAQoBA?= =?us-ascii?q?RcBAQQBAQoBAYMNAQEBAQF+L12OSZNTDpccJoV8AoIUEAEBAQEBAQEBAQEBEgE?= =?us-ascii?q?BAQoLCQodMIIzGgGCGwEFIxVRCxgCAiYCAlcGAQwGAgEBiHABCa8ygiWKMQwBJ?= =?us-ascii?q?YELhTqCAoFZgQaERoMFgl4FmwmBeoRcimuCR4dehjRIigKHdAI2gSlRg3qBanG?= =?us-ascii?q?IMgEBAQ?= X-IPAS-Result: =?us-ascii?q?A0AUAACJEW1YhyPMOLldFgYBAQQBAQoBARcBAQQBAQoBAYM?= =?us-ascii?q?NAQEBAQF+L12OSZNTDpccJoV8AoIUEAEBAQEBAQEBAQEBEgEBAQoLCQodMIIzG?= =?us-ascii?q?gGCGwEFIxVRCxgCAiYCAlcGAQwGAgEBiHABCa8ygiWKMQwBJYELhTqCAoFZgQa?= =?us-ascii?q?ERoMFgl4FmwmBeoRcimuCR4dehjRIigKHdAI2gSlRg3qBanGIMgEBAQ?= X-IronPort-AV: E=Sophos;i="5.33,459,1477954800"; d="scan'208";a="206948170" Received: from vrout30-bl.yaziba.net (HELO vrout30.yaziba.net) ([185.56.204.35]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Jan 2017 16:20:08 +0100 Received: from mtaout20.int.yaziba.net (mtaout20.int.yaziba.net [10.4.20.37]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by vrout30.yaziba.net (mx10.yaziba.net) with ESMTPS id D57E052237; Wed, 4 Jan 2017 16:20:07 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mtaout20.int.yaziba.net (Postfix) with ESMTP id BD979160333; Wed, 4 Jan 2017 16:20:07 +0100 (CET) X-Virus-Scanned: amavisd-new at mtaout20.int.yaziba.net Received: from mtaout20.int.yaziba.net ([127.0.0.1]) by localhost (mtaout20.int.yaziba.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yCXGjLWvf66f; Wed, 4 Jan 2017 16:20:07 +0100 (CET) Received: from [10.0.210.121] (unknown [185.23.92.144]) by mtaout20.int.yaziba.net (Postfix) with ESMTPSA id 653F91601CD; Wed, 4 Jan 2017 16:20:07 +0100 (CET) To: =?UTF-8?Q?Fran=c3=a7ois_Pottier?= , whitequark@whitequark.org, caml users References: <9576980c-9aad-4af2-e512-dc9c42743cf2@inria.fr> From: Alain Frisch Message-ID: <1e890adc-d031-8cba-27fd-eb0f69944c97@lexifi.com> Date: Wed, 4 Jan 2017 16:20:07 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <9576980c-9aad-4af2-e512-dc9c42743cf2@inria.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-DRWEB-SCAN: ok X-VRSPAM-SCORE: -100 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrfeelgedrudehgdejkecutefuodetggdotefrucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffgggjggtgfesthhqredttdefjeenucfhrhhomheptehlrghinhcuhfhrihhstghhuceorghlrghinhdrfhhrihhstghhsehlvgigihhfihdrtghomheqnecuffhomhgrihhnpehinhhrihgrrdhfrhenucfkphepudekhedrvdefrdelvddrudeggeenucfrrghrrghmpehmohguvgepshhmthhpohhuth X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht Subject: Re: [Caml-list] ppx_deriving question: deferring code generation? Hello Fran=C3=A7ois, I don't know if this would cover all similar cases, and perhaps it is a=20 bit verbose, but what about something like: include(struct type foo =3D Bar | Baz let x =3D ... end [@deriving visitors]) i.e. use an attribute on the module expression (and interpret it by=20 appending more declarations to the structure). Cheers, Alain On 04/01/2017 14:08, Fran=C3=A7ois Pottier wrote: > > Hello all, > > I am currently in the process of writing a ppx_deriving plugin, called > "visitors". Overall, this has been a pleasant experience; a few hundred > lines > of code have been sufficient to obtain nontrivial results. > > In normal use, the user writes something like this: > > type foo =3D > Bar | Baz > [@@deriving visitors] > > and some generated code is inserted just after the definition of the > type foo. > > However, I have reached a situation where the generated code cannot be > placed > just after the type definition. That is, I need to allow user-written > code to > appear after the type definition and before the generated code. > > For instance, this user-written code could be a declaration of a global > variable "x", whose type is "foo ref", and which the generated code > uses. The > declaration of "x" must appear after the definition of the type "foo", > because > the type of "x" mentions "foo". And the declaration of "x" must appear > before > the generated code, because the generated code (intentionally) refers to > "x". > > I am imagining that perhaps the user could write something like this: > > type foo =3D > Bar | Baz > [@@deriving visitors { delayed =3D true } > > let x : foo option ref =3D > ref None > > [@@visitors] > > The effect of the flag { delayed =3D true } would be to store the > generated code > somewhere in memory (instead of emitting right away), and the effect of t= he > floating attribute [@@visitors] would be to fetch that code from memory a= nd > emit it. > > To me, this seems somewhat ugly, but workable. Does ppx_deriving offer a > better approach? Does anyone have a better suggestion? Comments are > appreciated. > > Best regards, > > -- > Fran=C3=A7ois Pottier > francois.pottier@inria.fr > http://gallium.inria.fr/~fpottier/ >