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 C47227EE25 for ; Tue, 4 Jun 2013 10:22:02 +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: AioBAJWirVHB/BfUcmdsb2JhbABZgzkBvwWBFw4BDAgMCRQDJYIjAQEFOEARCw4KCRYPCQMCAQIBRQYBDAgBAYgNCL0bjy2DWAOXPoEphHWMeoE5 X-IPAS-Result: AioBAJWirVHB/BfUcmdsb2JhbABZgzkBvwWBFw4BDAgMCRQDJYIjAQEFOEARCw4KCRYPCQMCAQIBRQYBDAgBAYgNCL0bjy2DWAOXPoEphHWMeoE5 X-IronPort-AV: E=Sophos;i="4.87,798,1363129200"; d="scan'208";a="16673500" Received: from msa03.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.212]) by mail3-smtp-sop.national.inria.fr with ESMTP; 04 Jun 2013 10:22:02 +0200 Received: from [192.168.1.116] ([92.151.120.247]) by mwinf5d12 with ME id k8N01l00P5LMejg038N0tW; Tue, 04 Jun 2013 10:22:01 +0200 Message-ID: <51ADA3A8.7070008@frisch.fr> Date: Tue, 04 Jun 2013 10:22:00 +0200 From: Alain Frisch User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:22.0) Gecko/20100101 Thunderbird/22.0 MIME-Version: 1.0 To: David Allsopp , Romain Bardou , "caml-list@inria.fr" References: <51A81C67.50902@riken.jp> <87bo7rogub.fsf@gmail.com> <51A84283.80309@riken.jp> <51A868F8.9050101@inria.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] automatic extaction of the .mli (and a little more) from the .ml On 06/04/2013 09:53 AM, David Allsopp wrote: > I have wondered if this problem is perhaps looked at the wrong way > around - in other words, the complaint takes the form "how can we > export to the .mli file automatically" rather than "how can we > *import* from the .ml file automatically". The thing I do find > irritating maintaining .mli/.ml files is having to type anything out > twice - and for the most part that means fully exported type > declarations. Say you have a simple module: I'd rather do it the other way around: maintain the type declaration in the .mli and import it in the .ml file. And, guess what, there is also a POC of such a tool in the extension_points branch. It allows you to write in the .ml file: type t = [%copy_typedef] to copy the concrete definition from the .mli file. This also works for module types, and you can also import a definition from another .ml or .mli file: module type S = [%copy_typedef] type loc = [%copy_typedef "../../parsing/location.mli" t] The [%id ...] syntax is the other new syntactic feature introduced by the extension_points branch (in addition to attributes). Contrary to attributes which annotate already well-formed code and which can thus be ignored by the type-checker, [%...] extensions can used in place of an expression, type, pattern, etc, and they need to be expanded by a -ppx rewriter. The tool: http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/copy_typedef.ml?revision=HEAD&view=markup And an example: http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/test_copy_typedef.mli?revision=HEAD&view=markup http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/test_copy_typedef.ml?revision=HEAD&view=markup -- Alain