Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
RE: first class modules (was: alternative module systems)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-01-08 (17:56)
From: Claudio Russo <crusso@m...>
Subject: RE: first class modules (was: alternative module systems)
Hi again,

> > a few month ago, Markus Mottl pointed to this mailing list 
> the work by
> > Claudio Russo on first class modules. There were no answer 
> about plans to
> > implement such a system for OCaml.
> Well, it seems like Russo's first-class modules could be added with
> relatively little effort, if there is a sufficient need for them.
> (In OCaml and also in Luc Maranget's Hevea, I can see the need for
> conditionally selecting between several structures having the same
> signature; first-class modules give almost this but not quite.)

Why can't you do this with first-class modules?
In Moscow, you can write (note the somewhat different syntax designed to
co-exist with SML):

structure X as S = if toss_coin() then [structure Foo as S] else
[structure Bar as S];

It's a little redundant, but works.
If you want this to appear as a top-level or nested structure
declaration, then this does rely on 
integrating open with ordinary declarations,  but this is

> > As I see it, the main issue is the unification problem < S 
> > = < T >.
> Right.  The last time we met, I asked Claudio about type inference
> issues for his scheme.  Basically, to "unify" <S> and <T>, you just
> check that the module types S and T are equivalent (using the same
> notion of equivalence that OCaml currently uses to for checking
> compatibility between manifest module type declarations, see 
> the predicate
> Includemod.check_modtype_equiv in the OCaml sources).
> If <S> and <T> contain value components with non-generalized type
> variables, it is necessary to unify them along the way, and Claudio
> alluded to potential traps here.  However, I'm not even sure this can
> happen at all in OCaml since module types cannot contain n-g type vars
> and "pack" requires an explicit module type constraint.

This isn't quite true (unless you don't allow n-g vars in inferred
module types either).

fun f x = [structure struct val y = x end as sig val y:int end];
> val f = fn : int -> [{val y : int}]

applying the constraint should affect the type of x (which will be a
free var until the 
signature is matched against).

FYI, in Moscow you can even write, 

fun f (x:'a) = [structure struct val y = x end as sig val y:'a end];
> val 'a f = fn : 'a -> [{val y : 'a}]

so that f is polymorphic.
> > (as a side effect, we get the local "open ... in ...")
> I'm not sure I follow you here.  Did you mean that "open" and "pack"
> subsume "let module ... in ..."?  This I agree with.

I think the best approach is the other way around, treating open as
another form of declaration.

> - Xavier Leroy