Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search a hackage package for a function?

Maybe I am missing something, but is there a way to search inside some package on hackage?

Let's say I know that Snap framework has a function called render. How do I find it starting on it's hackage page: http://hackage.haskell.org/package/snap-0.9.0.1

like image 651
Andriy Drozdyuk Avatar asked Jun 26 '12 02:06

Andriy Drozdyuk


2 Answers

You can use Hoogle for this (as for so many other things) by using the +package search operator.

By default, Hoogle will search inside a standard set of packages by name or by type:

  • Searching for traverse will find:
    • traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)
      base Data.Traversable
    • traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
      base Data.Foldable
      Map each element of a structure to an action, evaluate these actions from left to right, and ignore the results.
    • … and so on
  • Searching for (a -> b -> c) -> f a -> f b -> f c will find:
    • liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
      base Control.Monad
      Promote a function to a monad, scanning the monadic arguments from left to right.
    • liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
      base Control.Applicative
      Lift a binary function to actions.
    • … and so on

Now, that's fine and dandy, but what about other packages? If you search for render, you find Render :: RenderMode from OpenGL, render :: Doc -> String from pretty, and some other things; the snap package isn't searched by default.

However, if you add +packagename or +Module.Name to your search, Hoogle will only search inside the specified packages (and -packagename and -Module.Name remove packages/modules from the search). Thus, searching for +snap render finds only the following three things:

  • render :: HasHeist b => ByteString -> Handler b v ()
    snap Snap.Snaplet.Heist
    Renders a template as text/html. If the given template is not found, this returns empty.
  • renderAs :: HasHeist b => ByteString -> ByteString -> Handler b v ()
    snap Snap.Snaplet.Heist
    Renders a template as the given content type. If the given template is not found, this returns empty.
  • renderWithSplices :: HasHeist b => ByteString -> [(Text, SnapletSplice b v)] -> Handler b v ()
    snap Snap.Snaplet.Heist
    Renders a template with a given set of splices. This is syntax sugar for a common combination of heistLocal, bindSplices, and render.

For more information on using Hoogle, you can check its manual on the Haskell wiki.

like image 73
Antal Spector-Zabusky Avatar answered Oct 10 '22 23:10

Antal Spector-Zabusky


Click on the link to some module in the package. Then in the top right, there is an index link. Click on that, and then on the link to the letter with which the desired function begins.

like image 31
Daniel Fischer Avatar answered Oct 11 '22 00:10

Daniel Fischer