ghc cyclic import error confusing

Evan Laforge qdunkan at gmail.com
Sat Apr 9 05:32:21 CEST 2011


I've found ghc's cyclic import error to be rather confusing, and I
finally took the time to understand why.  Here's an example:

Module imports form a cycle for modules:
 Cmd.Cmd (./Cmd/Cmd.hs)
   imports: Perform.Midi.Instrument Instrument.MidiDb Instrument.Db
 Perform.Midi.Instrument (./Perform/Midi/Instrument.hs)
   imports: Cmd.Cmd
 Instrument.MidiDb (./Instrument/MidiDb.hs)
   imports: Perform.Midi.Instrument
 Instrument.Db (./Instrument/Db.hs)
   imports: Instrument.Search Instrument.MidiDb
            Perform.Midi.Instrument
 Instrument.Search (./Instrument/Search.hs)
   imports: Instrument.MidiDb Perform.Midi.Instrument

It seems to be in a strange order and mentions extraneous modules.  I
would find this much easier to read:

Perform.Midi.Instrument -> Cmd.Cmd -> Instrument.MidiDb ->
Perform.Midi.Instrument

Instead, the order goes Cmd.Cmd -> Instrument.MidiDb, and then goes
backwards to Perform.Midi.Instrument -> Cmd.Cmd.  Then it goes forward
again to Instrument.MidiDb -> Perform.Midi.Instrument.  So the order
makes you jump around if you want to trace the import chain.  The
duplicated module that joins the cycle is not visually highlighted.
Whats more, it further confuses the eye by merging in multiple loops.
I suppose it could be useful to include additional loops, but I would
find it easier to read if they were included on their own line, such
as:

Cmd.Cmd -> Instrument.Db -> Instrument.Search ->
Perform.Midi.Instrument -> Cmd.Cmd

However, I think probably the shortest loop is the most interesting
one, and if there are multiple shortest loops, simply picking one
randomly is likely to be sufficient.

Thoughts?



More information about the Glasgow-haskell-users mailing list