Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any Haskell specific tools that can show source code from imported modules?

Tags:

haskell

ide

cabal

How can I browse Haskell source code preferably without internet connection? Right now I click through hackage search results, click source link and search the source page. There are two problems:

  • I'm using current version as a proxy of what I have locally
  • This does not work recursively well (another clicks and searches for next definition)

Usually IDEs let you download sources for any library and open new editor tab with definition. I prefer reading code than documentation, less surprises along the way and I can learn something from them.

So, how can I setup for recursive source searches using Haskell tools or standard GNU tools if necessary? All I know right now is that I can generate ctags for vim but where does cabal store sources?

like image 401
Rumca Avatar asked Feb 01 '14 14:02

Rumca


1 Answers

This is the opinionated workflow I follow to render the documentation with the source link enabled.

$ cd <package-name>
$ cabal sandbox init
$ cabal install --only-dependencies --enable-documentation --haddock-hyperlink-source
$ cabal configure --enable-documentation --haddock-hyperlink-source
$ cabal haddock --hyperlink-source
$ firefox dist/doc/html/<package-name>/index.html

The Source link should be enabled for all packages, including the dependencies, as long as they are installed in the sandbox.

In the particular case of Arch Linux, the distro I use, I try to avoid installing Haskell system packages through pacman because, by default, the documentation is not built with the source link enabled. In Arch Linux you can use ABS and modify the PKGBUILD with the parameters described above. I'm pretty sure something similar could be done in other distros, but have no idea about Windows or Mac OS X.

It's also worth mentioning that you don't need to type those parameters every time you run cabal. You can enable them by default in your .cabal/config

This should work without the sandbox but if you are dealing with more than one Haskell project I strongly recommend to use sandboxes.

like image 180
Danny Navarro Avatar answered Nov 15 '22 09:11

Danny Navarro