Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Circular module dependencies
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] Circular module dependencies
> Recently, there was a thread which talked about how difficult module
> dependencies were to resolve for linking in Ocaml.  I'm guessing this is
> because of cycles in the dependency graph.
>
> My thought is that maybe Ocaml shouldn't allow this to happen.  Wouldn't
> cyclical module dependencies be a symptom of bad design?  If a cyclic
> dependency occurs I can think of two ways of removing.
>
> First, if the dependency is among modules which are closely related, the
code
> in each module in the cycle which interacts, should be extracted into its
own
> module.   The cycle indicates code which is semantically related and would
> probably be easier to understand if it were all contained in the same file
> anyway.
>
> Second, if the cycle contains modules which aren't closely related, a new
> module should be created to encapsulate this dependency.  This could be
done
> using the Bridge pattern.  Since mutual dependencies make code brittle,
> explicitly revealing the cycle in a module makes the cycle more visible to
> the programmers and thus easier to deal with safely.
>
> Are there any examples of cyclic dependencies which shouldn't be handled
by
> either of these cases?

The theoric aspect of this approach are correct.
However in practice you end up sometimes with very big modules that you
would like to split into several files for the maintenance sake. This is
very difficult to do since you have to analyse the non-recursive parts of
your module, and you can't really split it in a logical way because you have
to care about the specific implementation you made which could create a
cycle. Think for instance someone programming in OO, where objects are
naturally recursive (structural subtyping helps to break cycles here, but
some can still remains). However in functionnal style this happen rarely,
but is still IMHO a needed feature, the possibility of having such following
wrong recursion being more rare and possible to detect at linking time :

--- module A
let x = A.x
--- module B
let x = B.x

Nicolas Cannasse


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