3

I've installed hoogle locally and have run hoogle generate.

If I run hoogle maybeToEither I get:

Data.Either.Utils maybeToEither :: MonadError e m => e -> Maybe a -> m a
Either maybeToEither :: Monoid b => (a -> b) -> Maybe a -> b
Network.Haskoin.Util maybeToEither :: b -> Maybe a -> Either b a

However if I use the web search I get a few more entries: https://hoogle.haskell.org/?hoogle=maybeToEither

Is there a way I can generate the same 'database' locally? Or is there possibly a CLI for searching https://hoogle.haskell.org?

According to https://wiki.haskell.org/Hoogle I should be able to run hoogle data or hoogle data all - but this seems do just do a search (so maybe outdated?).

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286

2 Answers2

1

This project might be of interest: https://github.com/andrevdm/bhoogle

I've also written bash function (depends on jq, fzf, xclip):

hoogle_searchAndCopy() {
  wget -qO- https://hoogle.haskell.org/\?hoogle\="$1"\&scope\=set%3Astackage\&mode\=json \
    | jq -r ".[] | \"import \\(.module.name)\\n\\(.package.name)\\n--\"" \
    | fzf | xclip ;
  }

hoogle_searchAndCopy maybeToEither results in:

enter image description here

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
1

I tried:

$ cabal update
$ cabal install hoogle
Installed hoogle-5.0.17.2
$ hoogle generate --download
$ hoogle maybeToEither

And got the response:

Data.Either.Utils maybeToEither :: MonadError e m => e -> Maybe a -> m a
Data.Either.Extra maybeToEither :: a -> Maybe b -> Either a b
Extra maybeToEither :: a -> Maybe b -> Either a b
Protolude.Either maybeToEither :: e -> Maybe a -> Either e a
Agda.Utils.Either maybeToEither :: Maybe a -> Either () a
Intro maybeToEither :: () => a -> Maybe b -> Either a b

At the moment the web shows 6 entries, because it has merged the Data.Either.Extra and Extra entries into one line as they refer to the same definition. Other than that, they match.

Note that hoogle generate generates a database based on what you have already downloaded, so if you run hoogle generate every month the result will not change. Adding --download forces Hoogle to download afresh.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85