Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find package, version, documentation for a Haskell name

Tags:

haskell

ghci

My concrete problem is this: I ran across the name throwT in Module.hs in a big Haskell project. I want to know what throwT does. I eventually managed to figure this one out as follows:

  1. fire up ghci for the project
  2. :load Module.hs followed by :i throwT throwT :: Monad m => e -> Control.Monad.Trans.Either.EitherT e m r -- Defined in ‘Data.EitherR’
  3. query hayoo for Data.EitherR, which points at the package errors
  4. ghc-pkg list errors gives errors-1.4.7
  5. browse hackage to the documentation of that version of the errors package: throwT

Is there a better way to do this, both in the sense of being more precise (step 3 is not), and less tedious?

like image 800
robx Avatar asked Aug 18 '15 09:08

robx


2 Answers

You could use ghc-pkg find-module instead of list, which gives you the installed version of the package containing the module right away:

  1. Fire up GHCi
  2. :load YourModule.hs, get :info on your value
  3. Use the given module name with ghc-pkg find-module.
  4. You now know the exact module, package and version.

This still forces you to check the hackage documentation. However, if you add documentation: true to your cabal configuration or --enable-documentation, cabal will automatically build the documentation during the installation of the given package. Then you can shorten the procedure to

  1. Fire up GHCi
  2. :load YourModule.hs, get :info on your value
  3. Check your local documentation for the references module.

The local documentation will be stored in your cabal directory, or, if you are in a sandbox, in .cabal-sandbox/share/doc/<plattform>/index.html.

like image 190
Zeta Avatar answered Nov 15 '22 06:11

Zeta


Ideally, every module explicitly imports every function it uses. Assuming that throwT was used in Module.hs, but not defined in it, the first thing to check for is if there is an import statement at the top of Module.hs that explicitly imports the function, which would look something like import Some-Module (throwT, someOtherFunction, possiblyAnotherFunction), where Some-Module is the module being imported, and the functions within the parenthesis are the only things being imported from that module (this is what an explicit import is). You'd then find Some-Module and look for the definition of throwT.

like image 45
Nicholas Montaño Avatar answered Nov 15 '22 06:11

Nicholas Montaño