caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Oliver Bandel <oliver@first.in-berlin.de>
Cc: Edgar Friendly <thelema314@gmail.com>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Why should I use .mli files?
Date: Wed, 31 Oct 2012 10:25:27 +0100	[thread overview]
Message-ID: <CAPFanBEHu6ZWm1j0zvsAAWjmnHB4NbsRRTBH18qhOK9yWVA+pA@mail.gmail.com> (raw)
In-Reply-To: <B4888D11-BF86-4756-B529-4D71486B2C8A@first.in-berlin.de>

> If I missed your pointm then you need to explain in more depth, what you mean.

My point of view is that you write .mli files, but then you don't want
to repeat in the .ml the concrete type definitions that have been
written in the .mli already. One problem with writing those concrete
(non-abstract) type definitions (and exceptions, class types and
module types) is that you have two places to edit instead of one when
you make a change, which increases the maintenance burden.

>> 2. The semantics of type-checking the .ml as a whole, and then
>> checking that it matches the .mli signature is sometimes inconvenient:
>> checking values against their .mli counterpart could help detect
>> typing mistakes sooner, which is helpful to get error messages that
>> are easier to understand

The current semantics is nice from a conceptual point of view (you
just need to explain how a .ml/.mli pair are understood as a module
with its interface, and then let the usual type-checking rule do the
work), but sometimes you would wish to have values type-checked
against their specification directly, rather than after the whole
module is type-checked. If the value has an unexpected type (compared
to the .mli signature), being warned at the value declaration site is
often better than at a (possibly remote) use site in the rest of the
module. The proposed semantics for having signature items in
structures allows to do this: every "let foo = ..." that comes after a
"val foo : bar" is type-checked under the expected type "bar".

>> 3. Some users want to have annotations on values (at least at
>> toplevel) for readability and the expression language is not optimal
>> for this (in particular the fact that type variables do not enforce
>> polymorphism)

The following code is valid:
  let f : 'a -> 'a = fun x -> x + 1

Beginners are often surprised by this. The language of type
annotations of OCaml is not simple, with three different ways to
enforce polymorphism, none of them obvious to the beginner. Value
signatures have a simple and non-surprising semantics that would
reject the following
  val f : 'a -> 'a
  let f x = x + 1

> I just suspect, that something important has been forgotten...

It's my turn to not understand what you say.

> If you don't use mli files, then the exported signiture
> is available and is like what you find inside the ml-file.
> So what is new here?

Allowing signatures items in structures and .ml files alone does not
increase the expressivity of the language. It is just a different way
to annotate names with expected types, that has the advantage of being
simple and predictable, and coincide with a syntax that users
sometimes wish they could use.
The new aspect of the proposal is the way it can be combined with the
(more debatable in itself) "module type" feature to avoid repeating
type definitions in the .ml. I believe the combination of these two
features is conceptually simpler than other approaches to this problem
(but not the recursive proposal of Alain which is very simple), and
has desirable other effects regarding the principled use of
annotations as signatures.

That said, I'm not clung to this proposal. I have been thinking about
it infrequently for a few weeks, and I'm still not satisfied with the
rather ad-hoc semantics of the "module type" feature. I was exposing
it as a contribution to the discussion, but I don't expect it to turn
into a submitted type-system patch right away.

On Tue, Oct 30, 2012 at 11:18 PM, Oliver Bandel
<oliver@first.in-berlin.de> wrote:
>
>
> Am 30.10.2012 um 22:25 schrieb Gabriel Scherer <gabriel.scherer@gmail.com>:
>
>> Independently of this discussion, I have been discussed related issues
>> with a friend for the last two weeks. I think there would be a feature
>> proposal to make in this area that would be *relatively* natural and
>> help solve the following different problems in this area:
>> 1. Repeating types, module types and class types declarations in the
>> .mli and the .ml is redundant and increases the maintenance burden
>
>
> Hmhh, not sure if Innserstand whatbyou mean.
> But as a mli-file narrows the default signature,
> repeating types mustbe done.
> An empty mli-file would create an empty signature,
> and IMHO thats good.
> Otherwise it would be necessary to have another mechanism to
> narrow the automatic copying of types.
>
> If I missed your pointm then you need to explain in more depth, what you mean.
>
>
>
>> 2. The semantics of type-checking the .ml as a whole, and then
>> checking that it matches the .mli signature is sometimes inconvenient:
>> checking values against their .mli counterpart could help detect
>> typing mistakes sooner, which is helpful to get error messages that
>> are easier to understand
>
> What is your argument? pro or contra?
> It looks weird to me.
>
>
>> 3. Some users want to have annotations on values (at least at
>> toplevel) for readability and the expression language is not optimal
>> for this (in particular the fact that type variables do not enforce
>> polymorphism)
>
> ??
>
>
>>
>> ## Proposal
>>
>> My suggestion would be to allow two features (the second depending on
>> the first):
>> 1. allow to insert signature items anywhere in a module structure or
>> .ml file, giving a reasonable semantics to it
>>    (in particular allow inclusion of signature as a structure item,
>> with the derived semantics)
>
>
> This is something that possibly would create a big mess,
> and also seems to mix up interface and implementation
> for the module language.
> At least thats my fear. Mybe if its well done, it would work.
>
> I just suspect, that something important has been forgotten...
>
>
>
>
>
>
>> 2. have a syntax to designate the mli signature from the ml file
>> (possible suggestion: "module type", used a signature expression)
>>
>> By combining the two features you could have something like
>>
>> a.mli
>>  type t = A | B of u
>>  type u
>>  val f : 'a -> 'a
>>
>> a.ml
>>  include (module type with type u = int)
>>  let f x = x
>
> ??
>
>
>>
>> But you could also write only a.ml:
>>  type t = A | B of u
>>  type u = int
>>  val f : 'a -> 'a
>>  let f x = x
>
> ??
>
>
> If you don't use mli files, then the exported signiture
> is available and is like what you find inside the ml-file.
> So what is new here?
>
> I,may missed the point, but you can omit mli-files today also....
>
> Ciao,
>    Oliver
>

  reply	other threads:[~2012-10-31  9:26 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-30  0:43 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
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 [this message]
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
     [not found] <fa.4zzWyGZIo+GsGOz7cSC34yWTunY@ifi.uio.no>
2012-10-31 14:32 ` Radu Grigore
     [not found] ` <fa.pEEaqh4bLDLiRdYkCRHvi9787TQ@ifi.uio.no>
     [not found]   ` <fa.JtZOlOTbNCp6rOoRnHhKEARwLDQ@ifi.uio.no>
     [not found]     ` <fa.s4gDOdOTZVbthjceZ5OEMxHiH90@ifi.uio.no>
     [not found]       ` <fa.rfsHI3X48Zri1S2pu1SEFowmDZg@ifi.uio.no>
     [not found]         ` <fa.KulHINoVpgjN1uI63QvwcxoNuiY@ifi.uio.no>
2012-11-01 11:38           ` Radu Grigore

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=CAPFanBEHu6ZWm1j0zvsAAWjmnHB4NbsRRTBH18qhOK9yWVA+pA@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=oliver@first.in-berlin.de \
    --cc=thelema314@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).