From: Romain Bardou <romain.bardou@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Re: Why should I use .mli files?
Date: Tue, 30 Oct 2012 14:31:31 +0100 [thread overview]
Message-ID: <508FD6B3.9080407@inria.fr> (raw)
In-Reply-To: <508FBCDC.5000104@gmail.com>
Usually the code you have to duplicate is type definitions which are not
private. If you don't want to copy-paste them, you can put them in a
separate file, which you open in the .mli and the .ml.
I often wished for this "private" or "public" keywords myself though.
But it's not clear what would be the best implementation. For instance:
type t = int
public let f x = x + 1
What should be the type of f in the inferred interface? "int -> int" or
"t -> int" or "t -> t" or "int -> t"? What about type t, should it be
"type t = private int" in the interface? Or "type t"?
Cheers,
--
Romain Bardou
Le 30/10/2012 12:41, Hongbo Zhang a écrit :
> Hi all,
> It's correct that .mli is great for third-party library, but it's not
> helpful for in-house library and agile-development. Sometimes I have
> .mli thousands of lines long, it's not fun to sync it up....
> That's why I filed a feature request which uses access modifier
> 'private' like F# http://caml.inria.fr/mantis/view.php?id=5764
> If you like the proposal, plz leave a comment to support it ;-)
> On 10/30/12 5:18 AM, Francois Berenger wrote:
>> On 10/30/2012 03:12 PM, Anton Lavrik wrote:
>>> Hi Francois,
>>>
>>> I don't use .mli files that much. Granted, I'm a rather casual OCaml
>>> user, but hey, at least you are not alone :)
>>>
>>> I'm surprised by some of the comments you've received. The fact that
>>> some people tend to practice top-down coding more than others doesn't
>>> really mean anything. Other people do it differently even regardless
>>> of the language they use. For me, paper and pencil are far more useful
>>> than .mli files up until the interfaces converge and stabilize.
>>>
>>> In general, .mli files are useful and even essential for libraries and
>>> large projects. For instance, they allow to clearly (and cleanly)
>>> define interfaces and help with separate compilation (i.e. to avoid
>>> recompiling parts).
>>>
>>> The biggest inconvenience with .mli files as I see it is that I have
>>> to repeat myself and make related but slightly different changes in
>>> two places when I change a module implementation. I would very much
>>> prefer to declare and document public interfaces next to the
>>> implementation and have language tooling take care of separate
>>> compilation and documentation generation.
>>
>> Thanks for pointing this out!
>>
>> The exact thing that would annoy me if I would adopt .mli files:
>> repeating myself.
>> In C, I used a tool call cproto to extract header files out of my .c
>> implementation code. Then, I just snipped out some parts of the header
>> I didn't want to make public, if I remember well.
>> That was not perfect, but at least I did not have to maintain two
>> files at the same time.
>>
>>> OCaml is kind of clumsy in this respect. For example, it does allow to
>>> specify types for values and function parameters inline. The syntax
>>> isn't the best, but the feature itself is very useful and I rely on it
>>> all the time. But when I get to define a type signature for a function
>>> e.g. in .mli file, I loose the ability to use parameter names and have
>>> to specify them in the comments.
>>>
>>> Overall, I count .mli files as a fairly minor language usability
>>> issue. Perhaps, it wouldn't be even very hard to fix, for example, by
>>> allowing something like "[public] val value-name : typexpr" in .ml
>>> files so that .mli/.cmi files can be generated automatically with
>>> desired public interfaces.
>>
>> I was thinking more about "export" as the keyword of choice,
>> but the functionality would be exactly the same.
>>
>> Best regards,
>> Francois.
>>
>>> Anton
>>>
>>>
>>> On Mon, Oct 29, 2012 at 7:43 PM, Francois Berenger <berenger@riken.jp>
>>> wrote:
>>>> Hello,
>>>>
>>>> Here is my stupid question of the day:
>>>> what's the use of those .mli files?
>>>>
>>>> Is it just to separate interface from implementation
>>>> so that the implementation of a module can be changed
>>>> without clients of its interface to have to bother?
>>>>
>>>> Does it make compilation of large software faster
>>>> by allowing for more parallelization and maybe later on avoiding to
>>>> recompile some parts?
>>>>
>>>> Usually I program in a pure functional style, so my modules
>>>> don't carry an internal state.
>>>> I feel like "if someone want to re-use a function, so be it".
>>>> If I really want to hide a function that I am afraid people
>>>> may call in an incorrect manner, I declare it internally
>>>> to some public function and use it correctly.
>>>>
>>>> Also, maybe I only work on toy-size OCaml projects. So, I never
>>>> bothrered to
>>>> create any .mli file.
>>>> I would like to know if I should bother about them.
>>>>
>>>> Thanks a lot,
>>>> Francois.
>>>>
>>>> --
>>>> 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
>>
>>
>
>
next prev parent reply other threads:[~2012-10-30 13:33 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-30 0:43 [Caml-list] " Francois Berenger
2012-10-30 1:04 ` Peter Groves
2012-10-30 2:21 ` Francois Berenger
2012-10-30 1:15 ` malc
2012-10-30 2:24 ` Francois Berenger
2012-10-30 10:23 ` malc
2012-10-30 1:19 ` Daniel Bünzli
2012-10-30 2:36 ` Francois Berenger
2012-10-30 3:26 ` Anthony Tavener
2012-10-30 12:28 ` Daniel Bünzli
2012-10-31 0:53 ` Francois Berenger
2012-10-30 2:21 ` gallais @ ensl.org
2012-10-30 6:12 ` Anton Lavrik
2012-10-30 9:18 ` Francois Berenger
2012-10-30 10:01 ` Malcolm Matalka
2012-10-30 11:03 ` Richard W.M. Jones
2012-10-30 11:41 ` [Caml-list] " Hongbo Zhang
2012-10-30 13:31 ` Romain Bardou [this message]
2012-10-31 1:03 ` Francois Berenger
2012-10-31 1:44 ` Daniel Bünzli
2012-10-31 9:51 ` Oliver Bandel
2012-10-30 14:32 ` [Caml-list] " Oliver Bandel
2012-10-30 14:45 ` Anton Lavrik
2012-10-30 14:49 ` Oliver Bandel
2012-10-30 14:51 ` Didier Cassirame
2012-10-30 14:47 ` Romain Bardou
2012-10-30 16:06 ` Edgar Friendly
2012-10-30 16:21 ` Romain Bardou
2012-10-30 16:46 ` Edgar Friendly
2012-10-30 21:25 ` Gabriel Scherer
2012-10-30 22:18 ` Oliver Bandel
2012-10-31 9:25 ` Gabriel Scherer
2012-10-31 9:59 ` Daniel Bünzli
2012-10-31 13:22 ` Edgar Friendly
2012-10-31 13:38 ` Daniel Bünzli
2012-10-31 13:55 ` Edgar Friendly
2012-10-31 13:43 ` Gabriel Scherer
2012-11-01 0:38 ` Francois Berenger
2012-11-01 0:42 ` Edgar Friendly
2012-11-01 0:52 ` Francois Berenger
2012-11-01 2:06 ` Edgar Friendly
2012-11-01 2:37 ` Francois Berenger
2012-11-01 2:44 ` Jacques Garrigue
2012-11-01 7:45 ` Andreas Rossberg
2012-10-31 10:20 ` Alain Frisch
2012-10-31 13:50 ` Edgar Friendly
2012-10-31 15:12 ` Gabriel Scherer
2012-10-31 16:48 ` Edgar Friendly
2012-10-31 17:15 ` Gabriel Scherer
2012-10-31 19:05 ` Tiphaine Turpin
2012-10-30 7:43 ` Mike Lin
2012-10-30 15:52 ` Didier Cassirame
2012-10-30 15:56 ` Romain Bardou
2012-10-30 16:14 ` Didier Cassirame
2012-10-31 21:30 ` Oliver Bandel
2012-11-01 15:26 ` Didier Cassirame
2012-10-31 15:32 ` Alain Frisch
2012-10-31 17:32 ` Tiphaine Turpin
2012-10-31 21:40 ` Oliver Bandel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=508FD6B3.9080407@inria.fr \
--to=romain.bardou@inria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox