Search code examples
haskellghci

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


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?


Solution

  • 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.