Top level mutable data structures problem

David Brown haskell at
Fri Oct 22 20:39:31 EDT 2004

On Fri, Oct 22, 2004 at 05:13:02PM -0700, John Meacham wrote:

> > What happens when there are cicular dependencies between modules.  Perhaps
> > the circular dependency is only because of sharing of types, and there is a
> > valid order for the initialization.  But, is it easy for the compiler to
> > determine this?
> I don't see a problem with letting the compiler run them in an arbitrary
> order. I don't see much need for ordering things intermodule as long as
> the actions are executed in order within each module. 

Although many programs will not depend on the ordering, others can.  What
if one module initialized a file, and another was expecting it to be setup
correctly.  Or, perhaps there is a shared IORef that needs to be
initialized.  Once IO is in the picture, the dependency computation can
become complex.

In general, if module A references module B, then module B's initialization
should have finished before module B's.  As long as there are no circular
references, it isn't difficult to come up with a valid ordering (aside from
references to external entities).  When A and B each refer to the other,
the compiler can't automatically determine which initialization must be
done first.


More information about the Glasgow-haskell-users mailing list