🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fa.caml
Article #54

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

#54
From: Romain Bardou
Date: Tue, 04 Jun 2013 08:24
69 lines
6061 bytes
Le 04/06/2013 09:53, David Allsopp a �crit :
> Romain Bardou wrote:
>> I also used to believe the .mli file should be somehow included in the .ml
>> file. Now I don't.
> 
> +1, FWIW! It's easy to start without the .mli when prototyping and then add it as things mature.
>  
>> 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.
> 
> This is horrible, IMO - any design decision which looks like it'll *require* refactoring support from an editor to be able to work with it strikes me as a bad design decision. If you have hundreds of these in a file, at some point you'll need a "renumber everything" macro.

Agreed, obviously. It seems Fran�ois proposes floats as a solution, but
while it does allow you to insert without renumbering everything, it
seems that with time, you'd end up with a messy file.

> 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 agree with the idea of looking the other way around, but I'm not sure
I agree with your proposal, which seems to *not* be the other way
around: in your example, you write "type t from implementation", in the
mli. I would prefer "type t from interface" from the .ml.

Also, I agree that val and let is not duplication as long as the let is
not annotated. Duplication comes from types and module type
declarations, exceptions, and maybe also classes.

Regarding val and let, if the types don't match, the error is better
located than before in recent versions of OCaml. But it could be even
better if the let could be retyped with inlined type annotations.

Here is an example:

val f: int -> int

let f x = x +. 1.

The error is located on f (it has type float -> float instead of int ->
int). But maybe it would be better if it was located on x or +. as if
the function was actually written like this:

let f (x: int): int = x +. 1.

Why do I bring that up? Well this would go in the sense of avoiding
duplication by avoiding the need of adding the type annotations yourself
to get better error location.

But this brings up other questions, such as: what if a function f is
polymorphic in the implementation and used as such, but is exported as a
monomorphic instance: if you import type annotations from the .mli, you
cannot use the polymorphism of f in the implementation anymore. Unless
the type annotations are only used to obtain better error messages, only
when there is a type mismatch between the mli and the ml.

Cheers,

-- 
Romain Bardou

-- 
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.TXTBzzTqj63EPYGcArMMbZ/jQyI@ifi.uio.no>
Path: arc1-ca.pugleaf.net!d5ni876pbl.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!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,start
X-Google-Attributes: gidc0fe4b917e,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII
X-Received: by 10.66.197.229 with SMTP id ix5mr3906734pac.23.1370334259407;
        Tue, 04 Jun 2013 01:24:19 -0700 (PDT)
Path: arc1-ca.pugleaf.net!d5ni876pbl.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!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: Tue, 04 Jun 2013 08:24:18 UTC
Organization: Internet mailing list
Lines: 69
Sender: caml-list-request@inria.fr
Message-ID: <fa.TXTBzzTqj63EPYGcArMMbZ/jQyI@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 1370334258 3245 129.240.7.9 (4 Jun 2013 08:24:18 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Tue, 4 Jun 2013 08:24:18 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
To: David Allsopp <dra-news@metastack.com>
X-IronPort-AV: E=Sophos;i="4.87,798,1363129200"; 
   d="scan'208";a="20202202"
X-Original-To: caml-list@sympa.inria.fr
Delivered-To: caml-list@sympa.inria.fr
X-IronPort-AV: E=Sophos;i="4.87,798,1363129200"; 
   d="scan'208";a="20201782"
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9CC7F39B8@Remus.metastack.local>
X-Enigmail-Version: 1.4.1
X-Validation-by: romain.bardou@inria.fr
X-Sequence: 6884
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:26 +0200
Original-Message-Id: <51ADA3C2.7020302@inria.fr>
Original-References: <51A81C67.50902@riken.jp> <87bo7rogub.fsf@gmail.com> <51A84283.80309@riken.jp> <51A868F8.9050101@inria.fr> <E51C5B015DBD1348A1D85763337FB6D9CC7F39B8@Remus.metastack.local>
Bytes: 5756
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit