caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Edgar Friendly <thelema314@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Why should I use .mli files?
Date: Wed, 31 Oct 2012 18:15:57 +0100	[thread overview]
Message-ID: <CAPFanBH84k8G++tE0b7=VmX2EmSBUoiqn1M_1131nHgshRFnsw@mail.gmail.com> (raw)
In-Reply-To: <50915650.3060904@gmail.com>

On Wed, Oct 31, 2012 at 6:32 PM, Tiphaine Turpin
<Tiphaine.Turpin@free.fr> wrote:
> Here is another proposal on this type topic : why not change the
> semantics of module type inclusion to consider missing types (and module
> types as well) as if they were declared with the same definition ? In
> other words, a signature S would be a subtype of S' if there exists some
> set of type declarations which, if prepended to S, make it have the type
> S' in the usual sense ? Exactly as [> `a ] is a subtype of [> `a | `b ]
> for polymorphic variants.

The problem with this idea is that you cannot ask yourself if "the
signature S (coming from the .mli) is a subtype of the signature S'
(coming from the .ml)" if the .ml, or the module definition, cannot be
type-checked without information coming from S. (S') doesn't exist
here, as the implementation cannot be type-checked by itself.

What you would need to do is recognize a contextual situation where
you type-check an implementation *given* a known signature context
(just as we extended type-checking expression to know about the
expected type for GADTs in 4.00), instead of type-checking it by
itself. This is essentially equivalent to the design considerations of
the (module type) feature that only makes sense in the context of a
larger signature sealing, only you're doing it implicitly.

(I think that once you realize that, you end up with something
equivalent to Edgar's proposal.)

On Wed, Oct 31, 2012 at 5:48 PM, Edgar Friendly <thelema314@gmail.com> wrote:
> I hope my solution is not only potentially simpler, but easier for people to
> use and more natural for people coming to OCaml from other languages where
> types are declared once.  It also allows us to sidestep the issue of type
> declarations and recursion, as it doesn't depend on any new syntax.

Convincing. I'll fight for having signature items usable in structures
(and forward references) another day, consider me a supporter of your
thought experiment.


On Wed, Oct 31, 2012 at 5:48 PM, Edgar Friendly <thelema314@gmail.com> wrote:
> On 10/31/2012 11:12 AM, Gabriel Scherer wrote:
>>>
>>> Maybe it's my over-exposure to C++ lately, but I see a clear semantic for
>>> type re-declaration:
>>> 1) It is only allowed to re-declare types from the auto-import of a
>>> module
>>> signature
>>> 2) abstract types can be re-declared arbitrarily
>>> 3) private foo types can be re-declared to foo
>>> Nothing else can be re-declared.
>
> I missed one case:
> 4) any type can be re-declared as itself.
> This uses up the one "re-declaration" that an auto-imported type is allowed.
>
>> Why not. We even have a syntax for explicit type overriding: "type! u =
>> int"!
>> (But if you want to preserve backward-compatibility and still make the
>> implicit inclusion of the interface in the implementation the default,
>> you need to allow innocent-looking definitions to have a rebinding
>> semantics.)
>
> Yes, the backwards compatibility is key to my proposal; existing .ml+.mli
> files would re-declare everything, resulting in all types being as listed in
> the .ml file.
>
>> I liked the idea of reusing the "with type ..." semantics instead of
>> introducing a new feature, but if this proposal can get rid of the
>> rather ad-hoc "module type" construct, you're trading one ad-hoc for
>> another ad-hoc yet potentially simpler feature. I would be happy with
>> such a langage feature.
>
> I hope my solution is not only potentially simpler, but easier for people to
> use and more natural for people coming to OCaml from other languages where
> types are declared once.  It also allows us to sidestep the issue of type
> declarations and recursion, as it doesn't depend on any new syntax.
>
> E.

  reply	other threads:[~2012-10-31 17:16 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
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 [this message]
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='CAPFanBH84k8G++tE0b7=VmX2EmSBUoiqn1M_1131nHgshRFnsw@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --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).