What Is Hoogle? Haskell Search Engine Explained

What Is Hoogle? Haskell Search Engine Explained

Quick Answer: What Is Hoogle?

Hoogle is a search engine specifically for Haskell APIs. But rather than search the entire web, it assists programmers in locating Haskell functions, types, modules and documentation for the Haskell library. The search can be performed either by a function name like map, or by a type signature, if one knows the required type of function but not its name.

Introduction

If you are learning Haskell, you will probably reach a point where you know what kind of function you need, but you have no idea what it is called.

That is where Hoogle becomes useful.

Instead of opening different package pages and searching through documentation one by one, you can type a function name or type into Hoogle and search across Haskell APIs from one place. It is basically a search tool built specifically for Haskell programmers.

The nice part is that you do not have to be an advanced Haskell developer to use it. You can start with simple word searches and get into type-based searches later.

How Does Hoogle Work?How Does Hoogle Work?

 

There are two main ways people use Hoogle. The first is just searching by name.

If you type:

  • map

Hoogle can show functions with that name and other closely related results, such as functions from different Haskell packages or modules.

The second way is more interesting. You can search using a Haskell type signature.

For example:

  • a -> a

This basically means, “Give me a function that takes one value and returns the same type of value.”

A result you may find is:

  • id:: a -> a

You do not need to know all the type-system details to understand the basic idea. The type tells Hoogle what kind of input and output you are looking for.

What You Want Search Example Result Idea
Find a function by name map Functions named or related to map
Find a function by type a -> a Functions matching that type shape
Search name and type id:: a -> a Results matching both

This is what makes Hoogle much more useful than a normal text search for Haskell code.

Why Is Searching by Type Useful?

This is probably the coolest part of Hoogle.

Sometimes you do not know the name of the function you need. You only know what it should take in and what it should return.

For example, imagine you want a function that takes another function, then takes a list, and gives you a new list.

You could search something like:

  • (a -> b) -> [a] -> [b]

That type is very close to the shape of map.

So instead of asking, “What was that function called again?” you can describe the kind of function you need through its type.

Honestly, once you get used to Haskell types, this can save quite a bit of time.

Hoogle also uses approximate type matching, so your query does not always need to be written in exactly the same way as the function’s real signature. That gives it a bit more flexibility.

What Does Hoogle Search?

The online version of Hoogle searches Haskell libraries and package documentation available through Stackage.

That means your results can include things like:

  • Functions
  • Types
  • Modules
  • Package documentation
  • Library APIs

You can also narrow a search if you only want results from a certain package or module.

For example, you may see searches using filters such as:

+bytestring concat

or:

fold +Data.Map

The + part helps limit the search to a package or module.

You do not need to learn all of these filters right away. For most beginners, typing a function name into Hoogle is enough to get started.

How Can You Use Hoogle?

The easiest way is to use the web version.

Open Hoogle in your browser, type what you are looking for, and check the results. That is probably all most people need at first.

But Hoogle can also be used in a few other ways:

  • Through the Hoogle website
  • From the command line
  • As a local installation
  • Through Haskell or JSON APIs
  • Inside some development tools and editor setups

Running Hoogle locally can be useful if you work with Haskell a lot or want faster searches against your own package setup.

Still, if you are just learning what Hoogle is, start with the website. No need to make it more complicated than it has to be.

Final Thoughts

Hoogle is basically a search engine for Haskell APIs.

You can use it to find functions by name, search documentation, and, more importantly, search by type signature when you know what a function should do but do not know its name.

That is really what makes Hoogle stand out.

If you are new to Haskell, start simple. Search function names first. Once types begin to make more sense, try searching by type signature too. It feels strange at first, but after a while it becomes one of those tools you are glad exists.