Difference between revisions of "Hoogle"

From HaskellWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
To use hoogle go to http://haskell.org/hoogle. Hoogle is a Haskell API search engine, written by [[User:NeilMitchell|Neil Mitchell]]. It allows you to search by either name, or by approximate type signature. To see how to use Hoogle see the [[/Tutorial|Tutorial]].
<!--
 
<center>
 
http://haskell.org/hoogle/res/hoogle_small.png
 
</center>
 
-->
 
 
To use hoogle go to http://haskell.org/hoogle. Hoogle is a Haskell API search engine, written by [[User:NeilMitchell|Neil Mitchell]]. It allows you to search by either name, or by approximate type signature.
 
   
 
== How to use Hoogle ==
 
== How to use Hoogle ==
  +
  +
This section details how to use the Hoogle program, it is more than just a command line tool or a website.
   
 
* The web interface: http://haskell.org/hoogle
 
* The web interface: http://haskell.org/hoogle
Line 14: Line 10:
 
* Download a command line version (yet to be released, but get the source and compile it yourself)
 
* Download a command line version (yet to be released, but get the source and compile it yourself)
 
* Hoogle is distributed with [[Lambdabot]]. Build a local [[Lambdabot]], and use its command line interface
 
* Hoogle is distributed with [[Lambdabot]]. Build a local [[Lambdabot]], and use its command line interface
* A Mac OS X version (unreleased yet, but it does exist)
 
   
 
== Integrating Hoogle and GHCi ==
== Examples ==
 
   
If you wanted to search for the standard prelude function <tt>map</tt>, you could type into the search any one of:
 
 
<pre>
 
(a -> b) -> [a] -> [b]
 
(a -> a) -> [a] -> [a]
 
(Int -> Bool) -> [Int] -> [Bool]
 
[a] -> (a -> b) -> [b]
 
</pre>
 
 
== Generating Hoogle databases ==
 
 
In essence, make haddock documentation for your thingy, then run hadhtml on the directory. hihoo is currently unsupported.
 
 
== Integrating hoogle and GHCi ==
 
 
Ever feel like having access to hoogle whilst messing around in GHCi? It's relatively easy to integrate the two. I'm on linux, so I don't know how well the following will work if you're on windows.
 
Ever feel like having access to hoogle whilst messing around in GHCi? It's relatively easy to integrate the two. I'm on linux, so I don't know how well the following will work if you're on windows.
   
First, you need to download and compile hoogle. Then, we want to move hoogle to somewhere in your system's <code>$PATH</code> (open a terminal and type <code>echo $PATH</code> to see where this is). I suggest ~/bin, although you might want to go for /usr/bin or /usr/local/bin, etc.
+
First, you need to download and compile Hoogle. Then, we want to move hoogle to somewhere in your system's <code>$PATH</code> (open a terminal and type <code>echo $PATH</code> to see where this is). I suggest ~/bin, although you might want to go for /usr/bin or /usr/local/bin, etc.
   
Copy the hoogle binary and hoogle.txt to the directory you chose. Now, there's a problem in that hoogle doesn't look for hoogle.txt in the system <code>$PATH</code>, it only looks in the current directory. This is a slight pain but is easily worked around: rename the hoogle binary to hoogle-bin, then create a new text file called 'hoogle' with the following contents:
+
Copy the Hoogle binary and hoogle.txt to the directory you chose. Now, there's a problem in that hoogle doesn't look for hoogle.txt in the system <code>$PATH</code>, it only looks in the current directory. This is a slight pain but is easily worked around: rename the hoogle binary to hoogle-bin, then create a new text file called 'hoogle' with the following contents:
   
 
#! /bin/bash
 
#! /bin/bash
Line 56: Line 37:
   
 
Hoogle can be called from Vim via the lambdabot vim scripts.
 
Hoogle can be called from Vim via the lambdabot vim scripts.
* Download and build [[Lambdabot]], which will also build a hoogle.
+
* Download and build [[Lambdabot]], which will also build a Hoogle.
 
* Install the scripts/vim programs into your path
 
* Install the scripts/vim programs into your path
   
Line 77: Line 58:
 
Prelude.fst :: (a, b) -> a
 
Prelude.fst :: (a, b) -> a
   
== Todo ==
+
== Hoogle databases ==
  +
  +
A Hoogle database has a list of functions and their types, they are plain text files. There are several approaches for generating Hoogle databases. Hoogle databases have the property that combining the files will still produce a valid database.
  +
  +
=== Haddock ===
  +
  +
The HEAD version of Haddock has a -hoogle flag which will generate a hoogle database. This is the prefered method of generating databases.
  +
  +
=== hadhtml ===
  +
  +
First make Haddock documentation for your system, then run hadhtml on the directory containing the HTML. The Hoogle database distribute with Hoogle was generated with hadhtml.
  +
  +
=== hihoo ===
  +
  +
This approach uses the .hi files generated by GHC, so has the potential for being most accurate, but is currently unsupported and does not work in lots of cases.
  +
 
== RoadMap ==
  +
  +
These are the future tasks, including fixing the remaining [[/Bugs]].
   
 
=== Admin ===
 
=== Admin ===
   
* Write a website build script
 
 
* get XHoogle in the repo
 
* get XHoogle in the repo
   
Line 111: Line 109:
 
* Integration with [[Cabal]]
 
* Integration with [[Cabal]]
 
* Integration with http://darcs.augustsson.net/Darcs/Djinn
 
* Integration with http://darcs.augustsson.net/Darcs/Djinn
  +
* Other languages than just Haskell, Clean etc.
   
 
=== Hoogle Suggest ===
 
=== Hoogle Suggest ===

Revision as of 18:35, 20 June 2006

To use hoogle go to http://haskell.org/hoogle. Hoogle is a Haskell API search engine, written by Neil Mitchell. It allows you to search by either name, or by approximate type signature. To see how to use Hoogle see the Tutorial.

How to use Hoogle

This section details how to use the Hoogle program, it is more than just a command line tool or a website.

Integrating Hoogle and GHCi

Ever feel like having access to hoogle whilst messing around in GHCi? It's relatively easy to integrate the two. I'm on linux, so I don't know how well the following will work if you're on windows.

First, you need to download and compile Hoogle. Then, we want to move hoogle to somewhere in your system's $PATH (open a terminal and type echo $PATH to see where this is). I suggest ~/bin, although you might want to go for /usr/bin or /usr/local/bin, etc.

Copy the Hoogle binary and hoogle.txt to the directory you chose. Now, there's a problem in that hoogle doesn't look for hoogle.txt in the system $PATH, it only looks in the current directory. This is a slight pain but is easily worked around: rename the hoogle binary to hoogle-bin, then create a new text file called 'hoogle' with the following contents:

#! /bin/bash
hoogle-bin -l /path/to/your/chosen/directory/hoogle.txt "$@"

chmod hoogle to make it executable (try chmod +x hoogle). Now you should be able to run hoogle requests from the shell. Try a few of the examples above.

Next, we need to integrate it into GHCi. We can execute shell commands with GHCi via :def. Load up GHCi, and type the following:

:def hoogle \x -> return $ ":!hoogle " ++ x

If this executes cleanly, you should be able to run hoogle commands from GHCi via :hoogle, i.e. :hoogle map or :hoogle "(a -> b) -> [a] -> [b]". Be careful: you need the extra quotes when hoogling types, at least on my system. :ho works as an abbreviation of :hoogle (just :h clashes with :help).

Finally, we want to make this persist across GHCi sessions. GHCi loads a file called ~/.ghci before running, so simply stick the above :def in that file and all should work.

DavidHouse

Using Hoogle From Vim

Hoogle can be called from Vim via the lambdabot vim scripts.

  • Download and build Lambdabot, which will also build a Hoogle.
  • Install the scripts/vim programs into your path

Then, to invoke hoogle from vim, passing the current buffer line or region as input:

!!bot hoogle

For example, if the buffer contains the line:

map

Running !!bot hoogle will replace that with:

Prelude.map :: (a -> b) -> [a] -> [b]
Data.IntMap.map :: (a -> b) -> IntMap a -> IntMap b
Data.IntSet.map :: (Int -> Int) -> IntSet -> IntSet

If the buffer contains:

(a,b) -> b

Running !!bot hoogle will replace that with:

Prelude.snd :: (a, b) -> b
Prelude.uncurry :: (a -> b -> c) -> (a, b) -> c
Prelude.fst :: (a, b) -> a

Hoogle databases

A Hoogle database has a list of functions and their types, they are plain text files. There are several approaches for generating Hoogle databases. Hoogle databases have the property that combining the files will still produce a valid database.

Haddock

The HEAD version of Haddock has a -hoogle flag which will generate a hoogle database. This is the prefered method of generating databases.

hadhtml

First make Haddock documentation for your system, then run hadhtml on the directory containing the HTML. The Hoogle database distribute with Hoogle was generated with hadhtml.

hihoo

This approach uses the .hi files generated by GHC, so has the potential for being most accurate, but is currently unsupported and does not work in lots of cases.

RoadMap

These are the future tasks, including fixing the remaining /Bugs.

Admin

  • get XHoogle in the repo

Short Term

i.e. before Hoogle3 goes public

  • Fix parse errors, ) ->, ) ->@ , func :: With Type
  • Regression tests for hoogle
  • You cannot search for certain keywords, i.e. @, because it is not a recognised lex symbol
  • Add comment characters, --, {- and -} to the list of symbols.
  • Put back more detailed information about the Prelude functions, see LibraryDocumentation.
  • Prelude.Either :: data Either a b -- the :: is entirely wrong
    • Prelude.Either data Either a b -- website
    • data Prelude.Either a b -- command line

Medium Term

  • Parameterise out by package, i.e. split off OpenGL
  • Compile with Yhc and distribute
  • Write GTK front end
  • Firefox/Mozilla plugin
  • Multiword search? power set
  • Dehack the Score program
  • Multiparameter type classes

Long Term

Hoogle Suggest

  • People often type to, instead of ->
  • Numeric literals
  • Concepts? tuple, random, monads etc.
  • Wrongly suggests capitals for t1 etc.
  • Kind errors, Maybe -> Bool, suggest Maybe a -> Bool
  • Return hits for module names ("Data" should return at least the module Data, probably known submodules as well)
  • People sometimes make typographical errors. Use a levenshtein distance edit on searches that have no result, to try to guess approximate answers by name (a la lambdabot's editing correction, here: http://www.cse.unsw.edu.au/~dons/code/lambdabot/Lib/Util.hs)