[Haskell-cafe] circular imports

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Mon Sep 6 23:48:56 EDT 2010

On 7 September 2010 03:44, Edward Z. Yang <ezyang at mit.edu> wrote:
> Excerpts from Evan Laforge's message of Mon Sep 06 13:30:43 -0400 2010:
>> I feel like the circular imports problem is worse in haskell than
>> other languages.  Maybe because there is a tendency to centralize all
>> state, since you need to define it along with your state monad.  But
>> the state monad module must be one of the lower level ones, since all
>> modules that use it must import it.  However, the tendency for bits of
>> typed data to migrate into the state means it's easy for it to
>> eventually want to import one of its importers.  And the state monad
>> module gets larger and larger (the largest modules in my system are
>> those that define state monads: 1186 lines, 706 lines, 1156
>> lines---the rest tend to be 100--300 lines).
> I have used hs-boot files to this effect.  I separated data and functionality,
> and typeclasses, which must be in the same module as data or are considered
> orphaned, get definitions via a circular import.

I'm just getting to the point where I have a similar problem.  I was
thinking about splitting instances off from the classes (and telling
GHC to not worry about orphaned instances for the instance-only
modules) but then realised that some instance declarations would be
circular as well, so I have to either use hs-boot files, define
everything in one big module and then re-export them in ways that make
sense or define all instances in one big module (at least for those
types which have circular deps among instances) and re-export

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list