3

I installed hoogle, using stack install hoogle. Now I can search for functions using a command like this from stack ghci:

:!hoogle --count=15 "[a] -> a"

I am in the root directory of my Yesod project - the main reason I installed it was to get help with Yesod functions - but when I try to find a function from Yesod like addHeader, it doesn't recognize a type defined on Yesod:

:t addHeader
addHeader :: MonadHandler m => Text -> Text -> m ()
:!hoogle --count=15 "MonadHandler m => Text -> Text -> m ()"
Warning: Unknown class MonadHandler
.
.
.

How can I setup hoogle to work beautifully with Yesod and also this very project I am working on, so that hoogle would bring my own functions and Yesod ones?

hao
  • 10,138
  • 1
  • 35
  • 50
FtheBuilder
  • 1,410
  • 12
  • 19

1 Answers1

3

You'll need to first get Hoogle to create you a yesod-core database:

λ> :!hoogle data yesod-core
0 warnings, saved to .warnings
Data generation complete

Then it just works!

λ> :!hoogle "+yesod-core MonadHandler m => Text -> Text -> m ()"
Yesod.Core.Handler addHeader :: MonadHandler m => Text -> Text -> m ()
Yesod.Core.Handler deleteCookie :: MonadHandler m => Text -> Text -> m ()
Yesod.Core.Handler setHeader :: MonadHandler m => Text -> Text -> m ()
Yesod.Core.Handler setSession :: MonadHandler m => Text -> Text -> m ()
Yesod.Core.Widget toWidgetMedia :: (ToWidgetMedia site a, MonadWidget m, HandlerSite m ~ site) => Text -> a -> m ()
Yesod.Core.Json (.=) :: KeyValue kv => forall v. ToJSON v => Text -> v -> kv

Yuck, the +yesod-core tag isn't great. Fortunately, we can combine our Hoogle databases into one big one:

$ cd ~/.stack/snapshots/x86_64-osx/lts-5.8/7.10.3/share/x86_64-osx-ghc-7.10.3/hoogle-4.2.43/databases 
$ mv default.hoo{,-prev}
$ hoogle combine *.hoo

(Your databases path will vary depending on whether you stack installed or cabal installed.)

λ> :!hoogle "addHeader"
Yesod.Core.Handler addHeader :: MonadHandler m => Text -> Text -> m ()
Network.CGI.Monad cgiAddHeader :: MonadCGI m => HeaderName -> String -> m ()

Way better than Google.

hao
  • 10,138
  • 1
  • 35
  • 50