From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5E9447F057 for ; Mon, 13 Oct 2014 16:54:33 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=pra; client-ip=193.252.23.212; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=mailfrom; client-ip=193.252.23.212; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@msa.smtpout.orange.fr) identity=helo; client-ip=193.252.23.212; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="postmaster@msa.smtpout.orange.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlIBAE/nO1TB/BfUm2dsb2JhbABbg2FYAcsoh0sCgTIBEQEBAQEBCAkLCRQuhAMBAQQ4QAEQCw4KCRYPCQMCAQIBRQYBDAEHAQGIPgnEaQEBAQEBAQEDAQEBAQEBAQEakEUHhEsBBJY7hxCBaoV8hHaLaYFFagEBgkgBAQE X-IPAS-Result: AlIBAE/nO1TB/BfUm2dsb2JhbABbg2FYAcsoh0sCgTIBEQEBAQEBCAkLCRQuhAMBAQQ4QAEQCw4KCRYPCQMCAQIBRQYBDAEHAQGIPgnEaQEBAQEBAQEDAQEBAQEBAQEakEUHhEsBBJY7hxCBaoV8hHaLaYFFagEBgkgBAQE X-IronPort-AV: E=Sophos;i="5.04,711,1406584800"; d="scan'208";a="83079079" Received: from msa03.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.212]) by mail3-smtp-sop.national.inria.fr with ESMTP; 13 Oct 2014 16:54:32 +0200 Received: from [192.168.1.132] ([92.151.36.93]) by mwinf5d28 with ME id 2euV1p00Z20adYC03euVR1; Mon, 13 Oct 2014 16:54:31 +0200 X-ME-Helo: [192.168.1.132] X-ME-Auth: bGV4aWZpQHdhbmFkb28uZnI= X-ME-Date: Mon, 13 Oct 2014 16:54:31 +0200 X-ME-IP: 92.151.36.93 Message-ID: <543BE7A5.5090208@frisch.fr> Date: Mon, 13 Oct 2014 16:54:29 +0200 From: Alain Frisch User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: Peter Zotov , Jun Furuse CC: caml-list , caml-list-request@inria.fr References: <8d73ce9dd0bb6d400565617d992736b5@whitequark.org> In-Reply-To: <8d73ce9dd0bb6d400565617d992736b5@whitequark.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] [ANN] ppx_overload : ppx for user definable SML style overloading On 10/13/2014 03:56 PM, Peter Zotov wrote: > On 2014-10-13 17:49, Jun Furuse wrote: >> Hi, >> >> I have OPAM-released ppx_overload, a ppx for user definable SML style >> overloading. > > Hi, > > Great hack! I wanted to do something similar, but yours is much more > elegant than what I had in mind. > > One note though: > >> Unfortunately this ppx trick does not work for the toplevel. It is >> since OCaml toplevel >> re-execute the ppx filter each time it gets a toplevel phrase. This >> makes the ppx filter >> hard to keep its state, in this case, the typing environment. > > In 4.02.1 the toplevel allows the ppx rewriter to save some state. > See > http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/trunk/parsing/ast_mapper.mli?view=markup#l192. And sedlex ( https://github.com/alainfrisch/sedlex ) illustrates one possible approach for storing the state. Instead of marshaling in any form some kind of internal state, it simply stores fragments of parsetree (here, structure items) that impacted its internal state and simply replay them on later phrases. (This is not very efficient, but for quick experiments in the toplevel, this is fine.) I don't know if this technique would apply to ppx_overload. -- Alain