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 B91B37FA5F for ; Mon, 30 Jan 2017 17:04:38 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.33,312,1477954800"; d="scan'208";a="211411581" Received: from unknown (HELO MP-41019.local) ([128.93.83.34]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 30 Jan 2017 17:04:38 +0100 To: Drup , caml-list@inria.fr References: <588B89B9.8000502@inria.fr> From: =?UTF-8?Q?Fran=c3=a7ois_Pottier?= Message-ID: <588F6415.4000900@inria.fr> Date: Mon, 30 Jan 2017 17:04:37 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] [ANN] visitors Hello, Le 27/01/2017 23:55, Drup a écrit : > Very nice! I wanted this for quite a while and the documentation is > excellent. Thanks! And thanks for your comments and pointers. > A big difference is that it load type definition from .cmi files directly. Indeed, a limitation of the ppx approach is that it is purely syntatic: a syntax tree (the type definition) is turned into a syntax tree (the definition of the visitor classes). In particular, at the moment, "visitors" cannot generate visitor classes for a pre-existing type. Perhaps one could write a tool that reads a .cmi file, but I suppose it would have to be explicitly invoked as an external tool. I will think about it. > What do you think of visitor that translates one datatype into another ? Well, the current package already allows this. If the two data types are just two distinct instances of a single parameterized data type, then a "map" visitor can do this, with very little effort. See the examples in the manual when "ordinary expressions" are converted to "hash-consed expressions" and back. If the two data types are unrelated, then, in order to translate the type "foo" to the type "bar", you need a "fold" visitor for the type "foo". You then have to manually implement each of the "build_" methods, so as to explain how each data constructor of the type "foo" should be translated. > I wonder if, given some annotations, it would be doable to use similar > techniques to generate visitors between different datatypes. I think you have it already, but instead of placing "annotations" in the type definition, you have to implement the "build_" methods. -- François Pottier francois.pottier@inria.fr http://gallium.inria.fr/~fpottier/