haskellmodulepackage

How do I find the Haskell package containing a particular module


Another elementary question about using GHC: finding the package containing a module when using existing code. This question has been asked several times here, but none of the answers seem to really address this basic issue.

I expected that the answer would be to use hackage, but the search facility is peculiar or perhaps under-documented.

Example: I have

import System.Random

So I visit hackage and try to search for System.Random with the search packages facility. I get back mersenne-random-pure64, randfile and normaldistribution. But not the random package which is what I am expecting from past experience.

Searching with just Random, however, does return the random package among many others. Which may suggest that "." is some sort of meta-character. But what, and why is there no documentation?

Somewhere, I saw that the search was in a package's metadata without defining the term metadata. I downloaded the random package tarball and looked at the contents and "System.Random" was in the description field of random.cabal among other places, so why can't Hackage see it?

Or is there some other way to identify a package or packages containing a particular module?


Solution

  • The usual approach is to search on Hoogle. A simple search for System.Random yields the module of that name in the random package as the first hit, plus other hits for the word "random" more generally that occur under the System hierarchy (not just modules, but classes and functions).

    However, you can refine the search to search only for modules using a tag. So a search for module:System.Random also yields that module in the random package as the first hit, as well as some additional System.Random.* modules from other packages.

    Update: The above refers to the Hoogle web site. To use a locally installed Hoogle, you'll need to install the Hoogle package (e.g., cabal install hoogle), generate a database (e.g., hoogle generate for a Stackage database), and launch a local web server on port 8080 (hoogle server) to get a full-featured interface. While there is a Hoogle command line interface, it seems rudimentary. As you mentioned in the comments hoogle module:System.Random will show "hits" without any package information, and while there's a semi-documented --info parameter that will dump additional information including the package name (hoogle --info module:System.Random), it inexplicably only displays information for the first search result. See this StackOverflow question for more.