简体   繁体   English

从 Hoogle 命令行访问函数的文档

[英]Accessing documentation for a function from Hoogle command line

When searching for a function on the Hoogle website , one sees the documentation associated with it, eg:Hoogle 网站上搜索某个函数时,会看到与之相关的文档,例如:

mod :: a -> a -> a            infixl 7

    integer modulus, satisfying

    (x `div` y)*y + (x `mod` y) == x

Hoogle also exists as a command line executable. Hoogle 也作为命令行可执行文件存在。 As far as I know, it only shows the signature of the function:据我所知,它只显示函数的签名:

~ ❯❯❯ hoogle --info Prelude.mod
Prelude mod :: Integral a => a -> a -> a

From package base
mod :: Integral a => a -> a -> a

Is there a way to get the associated documentation through the command line, as in the online version?有没有办法像在线版本一样通过命令行获取相关文档?

Use the -i option.使用-i选项。 It is not obvious how to get help for the default command ( search );如何获得默认命令 ( search ) 的帮助并不明显; here is how to do it:这是如何做到的:

$ hoogle search --help
Hoogle v4.2.41, (C) Neil Mitchell 2004-2012
http://haskell.org/hoogle

hoogle [search] [OPTIONS] [QUERY]
  Perform a search

Flags:
  -c --colour --color   Use colored output (requires ANSI terminal)
  -l --link             Give URL's for each result
  -i --info             Give extended information about the first result
  -e --exact            Match names exactly when searching
  -d --databases=DIR    Directories to search for databases
  -s --start=INT        Start displaying results from this point on (1 based)
  -n --count=INT        Maximum number of results to return
  -w --web[=MODE]       Operate as a web tool
  -r --repeat=INT       Run the search multiple times (for benchmarking)
Common flags:
  -? --help             Display help message
  -V --version          Print version information
     --numeric-version  Print just the version number
  -v --verbose          Loud verbosity
  -q --quiet            Quiet verbosity

With the -i flag, Hoogle will show the first result from the query along with its Haddock description:使用-i标志,Hoogle 将显示查询的第一个结果及其 Haddock 描述:

$ hoogle -i "nub"
nub :: (Eq a) => [a] -> [a]
base Data.List
O(n^2). The nub function removes duplicate elements from
a list. In particular, it keeps only the first occurrence of each
element. (The name nub means `essence'.) It is a special case
of nubBy, which allows the programmer to supply their own
equality test.

If you want to see the description of a result other than the first one, supply the fully qualified name:如果您想查看除第一个结果之外的其他结果的描述,请提供完全限定名称:

$ hoogle -i "Control.Foldl.nub"
nub :: Ord a => Fold a [a]
foldl Control.Foldl
O(n log n). Fold values into a list with duplicates removed,
while preserving their first occurrences

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM