Article View: fa.caml
Article #31Re: [Caml-list] automatic extaction of the .mli (and a little more) from the .ml
From: Romain Bardou
Date: Fri, 31 May 2013 09:10
Date: Fri, 31 May 2013 09:10
119 lines
6642 bytes
6642 bytes
I also used to believe the .mli file should be somehow included in the ml file. Now I don't. But if you design such a tool, here are some things to consider. - Using numbers to order stuff creates some issues of scalability. In particular, inserting a declaration between #3 and #4 may require you to move #4 to #5, #5 to #6 and so on, which (in particular if everything is not in the right order in the implementation) can prove more annoying than reordering stuff in an .mli. - Even without numbers it will be harder to get the big picture from a module. An approach I like about this is Pascal units, with an interface section and an implementation section, in the same file. But it does not solve the duplication issue. - You need a way to specify abstraction. For instance: * specify that a type should be exported as "type t" instead of "type t = A | B"; * specify that a type should be exported as "type t = private A | B" instead of "type t = A | B"; * specify that a value should be exported as "val f: t -> t" instead of "val f: int -> int" * specify that a value should be exported as "val f: int -> t" instead of "val f: 'a -> 'a" Often, people who want automatic .mli generation do not use abstraction, which is the main point of interfaces. - Don't forget that you need to take into account the whole OCaml language, including objects, modules, polymorphic variants� It may be more work than expected. And this project will need to be maintained and follow the changes to the language. Cheers, -- Romain Le 31/05/2013 08:26, Francois Berenger a �crit : > On 05/31/2013 02:31 PM, Malcolm Matalka wrote: >> I know of no such tool, but in counter to your premise: I used to think >> maintaining a .ml and .mli was foolish, however I no longer do. > > It itches me and it won't stop. > >> .mli is >> effectively documentation for me. It contains a lot of comments and is >> generally written to reflect how the API should be used rather than the >> order in which I must express functions to get ta .ml to compile. > > I'm proposing to add some number to tags so that things can > be reordered when dumped to the .mli. > >> On >> top of that, ocamlc will fail to compile if your .ml and .mli don't >> match, > > The tool I am thinking about is a preprocessor. > It would be used to generate all .mli files before the compilation > of the .ml ones (at least in _MY_ OCaml projects). > >> so it's a valuable check that what I think my module does is also >> what the compiler does. I also tend to write the .mli first, then write >> the .ml. I find it to be a great way to develop. > > I don't. > >> In short, I think it's a good thing to maintain these things by hand. > > I don't: > dumb_job + error_prone + can_be_automated + duplication_of_information > --> the computer will do it for me. > > I'm thinking about something small. > It may not work on all cases people can come up with. > I don't do very elaborated things usually so it will work for me, > at least. > >> But as for your original question I'm completely useless, sorry. >> >> /M >> >> Francois Berenger <berenger@riken.jp> writes: >> >>> Hello, >>> >>> Is there some recommended tool/script to generate a .mli >>> from the corresponding .ml? >>> >>> I want a little more than ocamlc -i: >>> >>> - I think there should be tags in the .ml file as comments >>> that say "export this" to the .mli. >>> By default, things are not exported. >>> - maybe it should have an option to say to replicate >>> the ocamldoc comments in the .mli. >>> - it could be nice if the order in which things are exported >>> to the .mli can be specified, maybe as an argument of the tag. >>> So that the .mli can be more readable (only backward references >>> to concepts, etc.) >>> >>> If there is a need to create a tool, let's call it "nomli". :) >>> >>> Regards, >>> F. >>> >>> PS: I'm not going to maintain both a .mli and a .ml. >>> I feel it is a dumb and error-prone job and that >>> itches me. >> > > -- 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.kLitjS6+thDvPu069t19jM9fjnc@ifi.uio.no>Path:
arc1-ca.pugleaf.net!fw11ni17335wic.0!nntp.google.com!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mailReferences:
<fa.ysPYFL5+u0NnfGu8UBtNleD9SeQ@ifi.uio.no> <fa.OQroQDVDk9br1ZhQEIL1NaakR5I@ifi.uio.no> <fa.bD6TGMY7hcijji7TE20fgVNMYJ0@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,CP1252
X-Received: by 10.180.11.239 with SMTP id t15mr1113124wib.3.1369991435715;
Fri, 31 May 2013 02:10:35 -0700 (PDT)
Path: arc1-ca.pugleaf.net!fw11ni17335wic.0!nntp.google.com!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail
From: Romain Bardou <romain.bardou@inria.fr>
Newsgroups: fa.caml
Subject: Re: [Caml-list] automatic extaction of the .mli (and a little more)
from the .ml
Date: Fri, 31 May 2013 09:10:35 UTC
Organization: Internet mailing list
Lines: 119
Sender: caml-list-request@inria.fr
Message-ID: <fa.kLitjS6+thDvPu069t19jM9fjnc@ifi.uio.no>
References: <fa.ysPYFL5+u0NnfGu8UBtNleD9SeQ@ifi.uio.no> <fa.OQroQDVDk9br1ZhQEIL1NaakR5I@ifi.uio.no> <fa.bD6TGMY7hcijji7TE20fgVNMYJ0@ifi.uio.no>
NNTP-Posting-Host: mail-jess.uio.no
Mime-Version: 1.0
X-Trace: readme.uio.no 1369991435 24052 129.240.7.9 (31 May 2013 09:10:35 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Fri, 31 May 2013 09:10:35 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12
To: caml-list@inria.fr
X-IronPort-AV: E=Sophos;i="4.87,777,1363129200";
d="scan'208";a="19750320"
X-Original-To: caml-list@sympa.inria.fr
Delivered-To: caml-list@sympa.inria.fr
X-IronPort-AV: E=Sophos;i="4.87,777,1363129200";
d="scan'208";a="19750243"
In-Reply-To: <51A84283.80309@riken.jp>
X-Enigmail-Version: 1.4.1
X-Validation-by: romain.bardou@inria.fr
X-Sequence: 6856
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: Fri, 31 May 2013 11:10:16 +0200
Original-Message-Id: <51A868F8.9050101@inria.fr>
Original-References: <51A81C67.50902@riken.jp> <87bo7rogub.fsf@gmail.com> <51A84283.80309@riken.jp>
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit