如何通过命令行使用hoogle搜索所有包?

时间:2018-03-24 17:08:04

标签: haskell hoogle

我已在本地安装了hoogle并运行了hoogle generate

如果我运行hoogle maybeToEither,我会:

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

但是,如果我使用网络搜索,我会收到更多条目:https://hoogle.haskell.org/?hoogle=maybeToEither

有没有办法可以生成相同的数据库'本地?或者是否可能有用于搜索https://hoogle.haskell.org

的CLI

根据https://wiki.haskell.org/Hoogle,我应该可以运行hoogle datahoogle data all - 但这似乎只是进行搜索(所以可能过时了?)。

2 个答案:

答案 0 :(得分:1)

此项目可能很有用:https://github.com/andrevdm/bhoogle

我也写了bash函数(取决于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导致:

enter image description here

答案 1 :(得分:0)

我试过了:

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

得到了答复:

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

目前,网络显示6个条目,因为它已将Data.Either.ExtraExtra条目合并为一行,因为它们引用相同的定义。除此之外,他们匹配。

请注意hoogle generate根据您已下载的内容生成数据库,因此如果您每月运行hoogle generate,结果将不会更改。添加--download迫使Hoogle重新下载。