Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Last active September 6, 2022 20:33
Show Gist options
  • Save chrisdone/78c1c1c052a853697cf3b902de086172 to your computer and use it in GitHub Desktop.
Save chrisdone/78c1c1c052a853697cf3b902de086172 to your computer and use it in GitHub Desktop.
stack hoogle

Introducing the stack hoogle feature!

With the release of hoogle5, we can now hoogle all local packages.

This let us implement stack hoogle, which is on the master branch of stack, but is not yet on a stack release. We'd like you to try it out before we do!

To upgrade to the latest stack from git, use:

$ stack upgrade --git

Or just run stack install in your local copy of the stack repo, if you have one.

Now, in any stack project, run:

$ stack hoogle map

After a bunch of setup work (see below), you'll get something like

bash-3.2$ stack hoogle map
map :: (a -> b) -> [a] -> [b]
map :: (Word8 -> Word8) -> ByteString -> ByteString
[..]

Pass -i to show documentation:

bash-3.2$ stack hoogle -- -i map
map :: (a -> b) -> [a] -> [b]
base Prelude
map f xs is the list obtained by applying f
to each element of xs, i.e.,


map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
map f [x1, x2, ...] == [f x1, f x2, ...]

Each project has its own installation of hoogle:

bash-3.2$ stack exec which hoogle
/Users/chris/Work/hs-popen/.stack-work/install/x86_64-osx/lts-5.3/7.10.3/bin/hoogle

Unless you install it globally, in which case it'll use the one in your PATH if it's >=5.0. So if you get sick of it installing copies of hoogle, do stack install hoogle-5.0.

Please give it a try!


Addendum: automatic installation process

Hoogle5 is probably not installed on your system, so you'll see this message:

Hoogle isn't installed or is too old. Automatically installing (use --no-setup to disable) ...

Minimum version is hoogle-5.0. Found acceptable hoogle-5.0 in your index, installing it.

After installing Hoogle5 it'll say:

No Hoogle database yet. Automatically building haddocks and hoogle database (use --no-setup to disable) ...

Then it'll run stack haddock and then stack hoogle -- generate --local.

If you see a message like

Packages not found: abstract-par aeson aeson-compat [..]

Don't worry about it; stack only generates haddocks for the things you're using in your project, whereas hoogle is looking at everything in the snapshot database.

Relatedly, if you add a dependency to your project, run stack hoogle --rebuild, and that'll generate the haddocks and the hoogle database again.

@saurabhnanda
Copy link

any chance this is integrated with Intero?

@CarstenKoenig
Copy link

I played with this a bit and I cannot get most of the documentation for the packages used in my project (for example mtl) - it says

Packages missing documentation: adjunctions aeson aeson-compat aeson-pretty aeson-qq ansi-terminal ansi-wl-pprint appar asn1-encoding asn1-parse asn1-types async attoparsec attoparsec-iso8601 auto-update base-compat base-orphans base-unicode-symbols base64-bytestring ...

with lots more including directly used ones.

How can I get them in?

@solicode
Copy link

solicode commented Aug 7, 2017

@CarstenKoenig I'm seeing the same thing ("Packages missing documentation" even for packages that I'm using). I see the files I'm looking for in PROJECT_ROOT/.stack-work/install/x86_64-osx/lts-9.0/8.0.2/doc/..., but I can't get to them through stack hoogle.

Maybe it's best to file an issue? I'm just not too sure whether it should go in stack or hoogle though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment