English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
[Caml-list] OCaml popularity
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-03-15 (20:16)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] Re: Haskell-like syntax
On Sat, Mar 15, 2003 at 11:58:46AM +0100, Markus Mottl wrote:

> Things are not this easy: the order is actually required for linking,
> not for compiling (as long as you provide explicit signatures in
> .mli-files).  The order during linking determines in which order side
> effects will be caused when values are initialized, which only the user
> can know. Furthermore, the "mutually recursive modules"-problem is more
> of a typing problem than one of compilation.

Ada has an interesting approach to this problem.  The Ada module system
is very similar to ocaml's.  However, they don't normally specify what
order things happen in (they call it elaboration order).  There are a
few directives you can put in source files to declare that something
else must be elaborated before the current module (package).

The GNU Ada compiler has a default mode that is much simpler, and much
more like how ocaml does it.  The elaboration order is determined by
statically analyzing the dependencies, performing a topological sort.
It doesn't work if there are circular dependencies, and you have to be
more explicit about elaboration.

They handle the circular dependencies by allowing the spec (the .mli
file) to come before the body (.ml) in the order.  This means that the
types, and names of functions are available early, but you can't call
them until that part has been loaded.

The other thing that Ada95 does well is their notion of child packages.
The child packages are compiled and elaborated independently of the
parents (well, after the parents).  For example, I have the modules A,
A.B, C and D.  C uses A, and D uses A.B, but A.B uses C.  The following
order would work.

  A  C  A.B  D

You could kind of think of compiling/linking module A.B just adds a new
child package to A.  After this, D is permitted to use A.B as well.
There is a conflict if A already has a definition for B.

I've thought about trying to throw this into ocaml.  The tricky part is
figuring out which .cmi files to look into for the information.  Perhaps
when you have a reference to A.B.xxx, you would first search for
a.b.cmi, and if not, look in a.cmi for the symbol.  (Gnu ADA also
changes all of the leading dots in the filenames to hyphens for systems
that don't like multiple dots in a name, so the name would be a-b.cmi).

Ada definitely has some annoying features, but there are some aspects of
the language that are well thought out (such as the module system).

Dave Brown

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners