caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Limitations of first-class modules
@ 2011-01-19 12:33 Lauri Alanko
  2011-01-19 22:02 ` [Caml-list] Generative functors how? Lauri Alanko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lauri Alanko @ 2011-01-19 12:33 UTC (permalink / raw)
  To: caml-list

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. 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.

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. This nominalism is quite surprising since one is
used to transparent definitions being just shorthands for signatures
that are compared structurally. In particular, this means that it is
no longer harmless to include a signature definition to compose a
convenience module from several submodules:

module A = struct 
  module type S = sig end
  type t = (module S)
  module M : S = struct end
  let v = (module M : S)
end

module B = struct
  include A
end

# module X : A.S = B.M;;
module X : A.S

# let x : A.t = B.v;;
Error: This expression has type (module B.S)
       but an expression was expected of type A.t = (module A.S)

Also, the limitations of package type constraints were also somewhat
surprising. The limitation about unpacking first-class modules in
functors was thankfully explained in the documentation, and it made
sense after a moment's reflection. No such rationale was included for
the rest of the design, so I'd be interested in hearing what's behind
it.


Lauri

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-01-21 12:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-19 12:33 [Caml-list] Limitations of first-class modules 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
2011-01-21 12:30   ` Jamie Brandon

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).