You are viewing brokenhut

The Broken Hut
Working my way up to a full-size building
Recent Entries 

Does anyone else have this problem? You get yourself into a programming groove and all is going swimmingly, and then suddenly think of some other project you could do as well. And the other project always seems tantalisingly trivial. “I’ll just devote a bit of time to it then I’ll come back to what I’m doing.” Naturally you never come back because — if you finish the distraction — you come up with something else new to do.

It’s quite infuriating. In this case, I was going to make an app for drawing import dependency diagrams for Haskell programs. I think it should be fairly easy.

At the top level I need to store a list of modules which have been processed and whatever still to go. A straighforward depth-first wouldn’t work because modules can be appear in several places. But for each file it seems to be a case of:

  1. Process Haskell code with GHC to delit it. Not relevant for most people but most of my code is literal.
  2. Drop all lines that don’t begin with import.
  3. Drop all hierarchical modules. I’ll just deal with flat modules at the moment; I can just strip off everything with a full stop in the name.
  4. Emit a directed-graph description of the form moduleA -> moduleB.

If I do all of that for each source file and wrap all the contents in the appropriate file format for graphviz, it should be fairly easy to create some nice graph pictures.

On further investigation it appears that the Function Graph Library (FGL) includes bindings for Graphviz. I think this task may have actually tipped over into the annoyingly trivial. But that’s okay, cos we’ve already established that if I did it I would just distract myself from other (already started) projects.

Another look at the documentation for the Glorious Haskell Compiler reveals that it should be easy to create a list of user-defined modules, using:

ghc -M Main.lhs

The -M flag makes it spit out a makefile-style dependency list. This is even simpler to splice up and pull out the relevant data, since all the delitting and import command isolation work has been done.

It’s nice when all the work is done for you, isn’t it? We’re sliding steadily towards “temptingly easy” now. I better watch myself…

This page was loaded Jul 12th 2014, 1:07 am GMT.