6

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?

duplode
  • 33,731
  • 7
  • 79
  • 150
nicolas
  • 9,549
  • 3
  • 39
  • 83
  • Are you looking for a plain text version of the module documentation? AFAIK haddock creates only HTML docs. – ErikR Dec 07 '14 at 12:02
  • yes, I wanted the same in the CLI than what there is on the website. – nicolas Dec 07 '14 at 12:06
  • 2
    side note : some nice configuration of hoogle here https://www.youtube.com/watch?v=QpDQhGYPqkU&list=PLxj9UAX4Em-Ij4TKwKvo-SLp-Zbv-hB4B&index=3 – nicolas Dec 07 '14 at 12:08

2 Answers2

5

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
duplode
  • 33,731
  • 7
  • 79
  • 150
luntain
  • 4,560
  • 6
  • 37
  • 48
3

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
duplode
  • 33,731
  • 7
  • 79
  • 150