> Now, as the module imports contain the cyclic dependencies, we have to
> *intrude into .hs files* :
> comment out some parts in Module1, Module2, compile them, un-comment
> some items in Module1, re-compile, and so on.
>
> Is there any easier way?
Dealing with mutually recursive modules is a pain, but the (under
documented) {-# SOURCE #-} pragma helps a bit by allowing you to break
up module loops.
If ghc sees an import decl of the form
import {-# SOURCE #-} Foo
it looks for the interface file Foo.hi-boot rather than Foo.hi. So,
assuming you've got a recursive dependency between modules Foo and
Bar, here's what you need to do:
- annotate the Foo import decl in Bar with {-# SOURCE #-}
- hand write Foo.hi-boot
- compute make dependencies
Bar will now depend on Foo.hi-boot, so the mutual dependency between
the two is broken.
How do you write an .hi-boot file? The easiest way to generate it
is probably to do as you describe above, and then look in Bar.hi
to see what it depends on from Foo.hi (compile with -Onot when doing
this to avoid too much junk from appearing in the interface files.)
Copy those exports from Foo.hi to Foo.hi-boot.
NOTE: If you change the signatures of any of the exports mentioned in
Foo.hi-boot in Foo.hs, you'll have to update Foo.hi-boot. (This is
a potential bug farm.)
If you decide to go ahead with .hi-boot files, the compiler sources
is a good starting point as it uses the {-# SOURCE #-} pragma
in a number of places.
Hope that helps,
--Sigbjorn