Ubiquitous Hoogle

Posted by Eric Kidd Mon, 01 Sep 2008 10:33:00 GMT

Ubiquity is an experimental Firefox plugin. It’s a “graphical command line” similar to QuickSilver on the Macintosh.

You can easily add your own commands to Ubiquity. The following article shows how to create a Hoogle search command that looks up Haskell functions by name or by type signature.

Searching for putStr

You can press Return or click on one the links in the preview.

Installing the easy way: Subscribing to the command

First, install Ubiquity. Then visit the command’s web page, and click Subscribe… when prompted by Firefox. You’ll see a scary warning screen, complete with source code. The button to install the command is at the bottom.

You can bring up Ubiquity by typing Option-Space (on the Mac) or Control-Space (everywhere else).

Installing manually: Creating the command

If you’d prefer to hack on your new command a bit, you also have the option of installing it manually.

Bring up the Ubiquity interface, and type in command-editor, press Return, and paste in the following code:

// Search Hoogle.  Based on Ubiquity's standard "Google" command.
  name: "Hoogle",
  url: "http://www.haskell.org/hoogle/?hoogle={QUERY}",
  icon: "http://www.haskell.org/hoogle/res/favicon.png",
  description: "Searches Hoogle for Haskell functions and types.",
  preview: function(pBlock, directObj) {
    if (!directObj.text || directObj.text.length < 1) {
      pBlock.innerHTML = "Searches Hoogle for the given function or type.";

    pBlock.innerHTML = "Searches Hoogle for <code>" + directObj.text + "</code>";

    var url = "http://www.haskell.org/hoogle/";
    var params = { hoogle: directObj.text, mode: "suggest" };

    jQuery.get(url, params, function(data) {
        var preview =
          "Searched Hoogle for <code>" + directObj.text + "</code>:";
        var results = data[1];
        for (var i = 0; i < results.length; i++) {
          var name = results[i];
          var url = "http://www.haskell.org/hoogle/?hoogle=" + escape(name);
          preview += "<br /><code><u><a href=\""+url+"\">" + name + "</a></u></code>";
        pBlock.innerHTML = preview;
    }, "json");

You don’t need to save the code. Ubiquity will do that for you automatically.

Searching for identifiers

Bring up Ubiquity, and start typing hoogle. The first two or three letters will generally be enough.

Searching for identifiers, no argument

Now start typing the identifier you want to search for:

Searching for putStr

Note that you can click on putStr or putStrLn in the window above, or simply press Return.

Searching for selected strings

You can also select a string anywhere on a web page and look it up using Hoogle.

Searching for selected text

Searching for types

You can search for Haskell functions by type signature. This doesn’t show any search results until you press Return, because Hoogle doesn’t offer search suggestions for type signatures.

Searching for types

What’s next?

Right now, this search command offers a very limited previews. With a bit of help from Hoogle, it would be easy to display type signatures, documentation, and other information in the preview window.

To do this, Hoogle would need a mode=preview command that returned the necessary information using JSON.

Many thanks to Neil Mitchell for Hoogle, and to the Ubiquity team for a useful new plugin!

Updated: Added new section on subscribing to the command.

Tags , ,


  1. Bryan O'Sullivan said 1 day later:

    Lovely stuff, thanks!

  2. Henri Losoi said 131 days later:

    Thanks for the great tip!

  3. Neil Mitchell said 192 days later:

    That looks great, I’ve filed a bug for your extension requests: http://code.google.com/p/ndmitchell/issues/detail?id=159

Comments are disabled