简体   繁体   English

Hoogle和yesod - 如何在非默认包中轻松查找功能

[英]Hoogle and yesod - how to easily find functions in non-default packages

I installed hoogle, using stack install hoogle . 我安装了hoogle,使用stack install hoogle Now I can search for functions using a command like this from stack ghci : 现在我可以使用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: 我在Yesod项目的根目录中 - 我安装它的主要原因是获得有关Yesod函数的帮助 - 但是当我尝试从Yesod中找到一个像addHeader的函数时,它无法识别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? 如何设置hoogle与Yesod以及我正在开发的这个项目工作得很漂亮,以便hoogle能够带来我自己的功能和Yesod的功能?

You'll need to first get Hoogle to create you a yesod-core database: 您需要首先让Hoogle为您创建一个yesod-core数据库:

λ> :!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. +yesod-core+yesod-core标签不是很好。 Fortunately, we can combine our Hoogle databases into one big one : 幸运的是,我们可以将我们的Hoogle数据库合并为一个大数据库

$ 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 install ed or cabal install ed.) (您的数据库路径将根据您是否stack install ed ed或cabal install而有所不同。)

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

Way better than Google. 方式比谷歌好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM