caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain.frisch@lexifi.com>
To: Lauri Alanko <la@iki.fi>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Limitations of first-class modules
Date: Thu, 20 Jan 2011 19:04:11 +0100	[thread overview]
Message-ID: <4D38791B.5070707@lexifi.com> (raw)
In-Reply-To: <20110119123335.GL323@melkinpaasi.cs.helsinki.fi>

On 01/19/2011 01:33 PM, Lauri Alanko wrote:
> When first-class modules were announced for OCaml 3.12, I cheered them
> as a sorely needed extension, and I have now begun to make heavy use
> of them. I certainly prefer them over objects, even if I do find the
> syntax of first-class modules a bit awkward.

As Jacques mentioned, OCaml 3.13 will allow a lighter syntax, with a lot 
less explicit type annotations. Hopefully, this will make it less awkward.

> I would much prefer to
> see a completely unified object-module system a la Scala, but I guess
> such drastic changes are beyond the scope of OCaml's development
> nowadays.

Indeed.

> Anyway, I'm now beginning to stumble into the limitations of the
> extension, and I'm a bit curious about their rationale.
>
> In a type (module S), S must be a path to a named module type, and if
> A and B are two different paths, (module A) and (module B) are
> distinct even if A and B are transparent definitions for exactly the
> same module types.

One could indeed declare that (module A) and (module B) are equal
as soon as A and B refer to equal module types (that is, two module 
types subtype of each other without any coercion). I don't think there 
is any deep obstacle in doing that. One would need to be a little bit 
careful with mutually recursive types and module types (introduced with 
a recursive module).  As for the implementation strategy, I'm a little 
bit concerned of having a low-level module in the type-checker (Ctype), 
in charge of things like type equality check or unification, calling a 
function in a higher-level module (Includemod), but I don't see 
immediately any concrete problem in doing that.

What would be much more difficult is to declare that general package 
type (with constraints, like (module A with type t1 = T1)) are equal if 
the module types obtained by "applying the constraints" are equal. 
Indeed, the type T1 above can contain type variables, and a constraint 
"with type t1 = T1" is then not supported by the module system (there is 
no module type with free type variables).


There is a branch fstclassmod_parametrized in the SVN which allows more 
kinds of constraints; in particular, it allows constraints on 
parametrized types (module A with type 'a t1 = T1). See e.g.

http://caml.inria.fr/mantis/view.php?id=5078

This extension does not seem very useful to me in practice (because 
there is no polymorphism on type constructors in OCaml). Moreover, it 
isn't trivially combined with Jacques' work mentioned above. So it's 
probably not going to be integrated upstream.


Feel free to open entries in the bug tracker with specific examples of 
things you'd like to do but which are not possible or difficult with the 
current design.  My initial work on first-class modules was driven by 
our internal use at LexiFi (for which the nominal aspect has never been 
a problem) and also by the constraint of keeping the patch small enough 
(to increase the odds of being accepted upstream).



Alain

  parent reply	other threads:[~2011-01-20 18:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-19 12:33 Lauri Alanko
2011-01-19 22:02 ` [Caml-list] Generative functors how? Lauri Alanko
2011-01-20  1:43 ` [Caml-list] Limitations of first-class modules Jacques Garrigue
2011-01-20 18:04 ` Alain Frisch [this message]
2011-01-21 12:30   ` Jamie Brandon

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=4D38791B.5070707@lexifi.com \
    --to=alain.frisch@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=la@iki.fi \
    /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).