When searching for a function on the Hoogle website, one sees the documentation associated with it, e.g.:
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. 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?
luntain
Use the -i
option. It is not obvious how to get help for the default command (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:
$ 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
来源:https://stackoverflow.com/questions/27341956/accessing-documentation-for-a-function-from-hoogle-command-line