Difference between revisions of "Hoogle"

From HaskellWiki
Jump to navigation Jump to search
(fixups to hoogle/ghci integration)
Line 33: Line 33:
 
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 $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.
+
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 $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:
+
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
 
hoogle-bin -l /path/to/your/chosen/directory/hoogle.txt $@
 
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.
+
chmod hoogle to make it executable (try <code>chmod +x hoogle</code>). 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:
+
Next, we need to integrate it into GHCi. We can execute shell commands with GHCi via <code>:def</code>. Load up GHCi, and type the following:
   
 
:def hoogle \x -> return $ ":!hoogle " ++ x
 
: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"'. Be careful: you need the extra quotes around the parameters (a minor disavantage to this technique).
+
If this executes cleanly, you should be able to run hoogle commands from GHCi via <code>:hoogle</code>, i.e. <code>:hoogle map</code> or <code>:hoogle "(a -> b) -> [a] -> [b]"</code>. Be careful: you need the extra quotes when hoogling types, at least on my system. <code>:ho</code> works as an abbreviation of <code>:hoogle</code> (just <code>:h</code> clashes with <code>:help</code>).
   
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.
+
Finally, we want to make this persist across GHCi sessions. GHCi loads a file called ~/.ghci before running, so simply stick the above <code>:def</code> in that file and all should work.
  +
  +
[[User:DavidHouse|DavidHouse]]
   
 
== Todo ==
 
== Todo ==

Revision as of 19:01, 17 March 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.

How to use Hoogle

  • The web interface: http://haskell.org/hoogle
  • The Lambdabot plugin, @hoogle and @hoogle+
  • Download the source with Darcs (where did i put it again?)
  • Download a command line version (yet to be released, but get the source and compile it yourself)
  • A Mac OS X version (unreleased yet, but it does exist)

Examples

If you wanted to search for the standard prelude function map, you could type into the search any one of:

(a -> b) -> [a] -> [b]
(a -> a) -> [a] -> [a]
(Int -> Bool) -> [Int] -> [Bool]
[a] -> (a -> b) -> [b]

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.

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

Todo

Admin

  • Write a website build script
  • 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.

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

Bad Searches

  • (a -> b) -> ([a] -> [b]) -- should find map
  • a->b->a -- does not work because no spaces (should do!)
  • @hoogle Data.IntMap.IntMap a -> [a] -- badly kills the module names
  • @hoogle -- , gives copyright message (consequence of argument parsing in command line)

Higher Kinds

The following searches are all wrong because Hoogle doesn't understand higher kinds, i.e. Monad's.

  • Functor f => (a -> b) -> f a -> f b -- should find fmap
  • Monad m => [m a] -> m [a] -- should find sequence
  • (Monad m) => m (m a) -> m a -- should find join

Problems

While trying to run hihoo.pl on the NewBinary library, I received the following problems

hihoo is currently unmaintained, I recommend hadhtml. If someone is able to fix it up... --Neil Mitchell 19:22, 13 February 2006 (UTC)
*** can't parse data or newtype declaration:
data MBA
    Variances []
    RecFlag NonRecursive
    Generics: no
    {- abstract -}
*** can't parse data or newtype declaration:
data Bin a
    Variances [(False, False)]
    RecFlag NonRecursive
    Generics: no
    {- abstract -}
*** can't parse data declaration:
data BinHandle
    Variances []
    RecFlag NonRecursive
    Generics: no
    = BinMem NewBinary.FastMutInt.FastMutInt{1}
             NewBinary.FastMutInt.FastMutInt{1}
             (GHC.IOBase.IORef BinArray)
             NewBinary.FastMutInt.FastMutInt{1}
             NewBinary.FastMutInt.FastMutInt{1}
          Stricts: ! ! ! ! !
          Fields: off_r sz_r arr_r bit_off_r bit_cache_r |
      BinIO NewBinary.FastMutInt.FastMutInt{1}
            GHC.IOBase.Handle
            NewBinary.FastMutInt.FastMutInt{1}
            NewBinary.FastMutInt.FastMutInt{1}
          Stricts: ! ! ! !
          Fields: off_r hdl bit_off_r bit_cache_r
*** can't parse data or newtype declaration:
data FastMutInt
    Variances []
    RecFlag NonRecursive
    Generics: no
    {- abstract -}

Hoogle in my path

If hoogle is put in teh path, hoogle.txt is still looked for in the current directory, thats just braindead.