[Haskell-beginners] cyclic imports

Christopher Howard christopher.howard at frigidcode.com
Thu Sep 13 01:22:16 CEST 2012


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120912/8444a298/attachment.pgp>


More information about the Beginners mailing list