🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fa.caml
Article #53

Re: [Caml-list] automatic extaction of the .mli (and a little more) from the .ml

#53
From: Alain Frisch
Date: Tue, 04 Jun 2013 08:22
53 lines
4982 bytes
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

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Technical Details
Message-ID: <fa.vZ9CoH7+DZuJ8+hvyvnnFAinU3A@ifi.uio.no>
Path: arc1-ca.pugleaf.net!d5ni802pbl.0!nntp.google.com!news.glorb.com!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail
References: <fa.ysPYFL5+u0NnfGu8UBtNleD9SeQ@ifi.uio.no> <fa.OQroQDVDk9br1ZhQEIL1NaakR5I@ifi.uio.no> <fa.bD6TGMY7hcijji7TE20fgVNMYJ0@ifi.uio.no> <fa.kLitjS6+thDvPu069t19jM9fjnc@ifi.uio.no> <fa.1Prz+i/q1iTOfA4HYPhd0lmmYco@ifi.uio.no>

Show Full Headers
Complete Article Headers
X-Google-Thread: c0fe4b917e,bcac4a6e27ff55dd
X-Google-Attributes: gidc0fe4b917e,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
X-Received: by 10.66.12.196 with SMTP id a4mr3904641pac.9.1370334132567;
        Tue, 04 Jun 2013 01:22:12 -0700 (PDT)
Path: arc1-ca.pugleaf.net!d5ni802pbl.0!nntp.google.com!news.glorb.com!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail
From: Alain Frisch <alain@frisch.fr>
Newsgroups: fa.caml
Subject: Re: [Caml-list] automatic extaction of the .mli (and a little more)
 from the .ml
Date: Tue, 04 Jun 2013 08:22:12 UTC
Organization: Internet mailing list
Lines: 53
Sender: caml-list-request@inria.fr
Message-ID: <fa.vZ9CoH7+DZuJ8+hvyvnnFAinU3A@ifi.uio.no>
References: <fa.ysPYFL5+u0NnfGu8UBtNleD9SeQ@ifi.uio.no> <fa.OQroQDVDk9br1ZhQEIL1NaakR5I@ifi.uio.no> <fa.bD6TGMY7hcijji7TE20fgVNMYJ0@ifi.uio.no> <fa.kLitjS6+thDvPu069t19jM9fjnc@ifi.uio.no> <fa.1Prz+i/q1iTOfA4HYPhd0lmmYco@ifi.uio.no>
NNTP-Posting-Host: mail-jess.uio.no
Mime-Version: 1.0
X-Trace: readme.uio.no 1370334132 3009 129.240.7.9 (4 Jun 2013 08:22:12 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Tue, 4 Jun 2013 08:22:12 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:22.0) Gecko/20100101 Thunderbird/22.0
To: David Allsopp <dra-news@metastack.com>, 
 Romain Bardou <romain.bardou@inria.fr>,
 "caml-list@inria.fr" <caml-list@inria.fr>
X-IronPort-AV: E=Sophos;i="4.87,798,1363129200"; 
   d="scan'208";a="20201633"
X-Original-To: caml-list@sympa.inria.fr
Delivered-To: caml-list@sympa.inria.fr
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"
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9CC7F39B8@Remus.metastack.local>
X-Sequence: 6883
X-no-archive: yes
List-Id: <caml-list.inria.fr>
List-Archive: <http://sympa.inria.fr/sympa/arc/caml-list>
List-Help: <mailto:sympa_inria@inria.fr?subject=help>
List-Owner: <mailto:caml-list-request@inria.fr>
List-Post: <mailto:caml-list@inria.fr>
List-Subscribe: <mailto:sympa_inria@inria.fr?subject=subscribe%20caml-list>
List-Unsubscribe: <mailto:sympa_inria@inria.fr?subject=unsubscribe%20caml-list>
Original-Date: Tue, 04 Jun 2013 10:22:00 +0200
Original-Message-Id: <51ADA3A8.7070008@frisch.fr>
Original-References: <51A81C67.50902@riken.jp> <87bo7rogub.fsf@gmail.com> <51A84283.80309@riken.jp> <51A868F8.9050101@inria.fr> <E51C5B015DBD1348A1D85763337FB6D9CC7F39B8@Remus.metastack.local>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit