
In my app, I have a class definition and a data type definition that depend on each other: code: -------- class (InternallyUpdating a) => Transient a where {- Whether or not the object should be removed from existence -} expired' :: a -> Maybe [AfterEffect] data AfterEffect = forall a. ( Animation a , Transient a ) => VisualEffect a -- to be extended algebraically... -------- It's written in this somewhat recursive manner so that one effect can give rise to another effect when it is completed. This code compiles just fine when the two definitions are in the same file. However, if I separate them out to different modules, each module most import the other, resulting in this error: code: -------- Module imports form a cycle: module `AfterEffect' (AfterEffect.hs) imports `Updating' (./Updating.hs) which imports `AfterEffect' (AfterEffect.hs) -------- As a point of curiosity, at least, I'm wondering why GHC does not allow mutally-dependent imports, as recursive dependencies doesn't seem to be a problem in any other area of Haskell. And I'm wondering if there is some kind of trick to get around this and allow the cyclic dependency. -- frigidcode.com indicium.us

On Thu, Sep 13, 2012 at 1:22 AM, Christopher Howard < christopher.howard@frigidcode.com> wrote:
As a point of curiosity, at least, I'm wondering why GHC does not allow mutally-dependent imports, as recursive dependencies doesn't seem to be a problem in any other area of Haskell. And I'm wondering if there is some kind of trick to get around this and allow the cyclic dependency.
Allowing mutually-dependent imports in all generality would complicate the task of GHC name resolution and type inference but if you're ready to do a bit more work, you can have cyclic dependency with an hs-boot file, see GHC doc : http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation... -- Jedaï
participants (2)
-
Chaddaï Fouché
-
Christopher Howard