Generating Haskell module dependency tree

Viewed 201

Is there a way I could generate (and view) the module dependency tree of my Haskell project? I've seen images of such graphs but am unable to dlfigure out how it could be done.

2 Answers

For Haskell stack, you can let stack write a GraphViz dot file for the dependency graph with:

stack dot --external

The --external flag means it will include dependencies not defined in your stack project. You can for example use I/O redirection to write it to a file with:

stack dot --external > deps.dot

and then use dot as a tool to convert this to an image, for example with:

dot -Tpng deps.dot -odeps.png

You can also make use of -Tsvg, -Tgif, etc. to pick another image format.

For more information, see the dependency visualization section of the documentation.

You can get a graph of a project's modules with yav/graphmod:

cabal install graphmod

The in your project:

~/.cabal/bin/graphmod | dot -Tpng > modules.png

You can see more options with ~/.cabal/bin/graphmod --help, change the output format with options to dot, and see examples here.

Related