如何在 GHCI 中查找多个导入方法的类型签名

发布于 2024-10-21 16:11:36 字数 566 浏览 7 评论 0原文

我正在使用一个库,已将其加载到 GHCI 中。

从函数的名称来看,我并不清楚应该使用哪一个;我确信它存在,并且希望查看我可用的函数的类型签名列表。我不知道该怎么做。

  • 我可以通过键入模块名称并在 GHCI 中使用制表符补全来获取库导出的所有函数的列表。
  • Hoogle 对我来说毫无用处,因为有问题的库没有被涵盖。不过,胡格尔风格的搜索会很有用。
  • 我知道 GHCI 的 :t,但它似乎只适用于单个函数,而且我不想对库导出的每个函数都执行此操作。
  • 在源目录上运行 grep -R :: ./* 或类似的命令可能会忽略没有显式类型签名的函数。
  • 该库有 Haddock 文档,但它有大约 1000 个函数,分布在数十个子模块中,手动搜​​索所有函数非常繁琐且容易出错。

我愿意尝试任何方法,但显然更喜欢简单、可移植和可重复的方法。

有没有办法找到库中所有导出函数的类型签名?或者找出哪些函数具有包含特定类型的类型签名?

I'm using a library, which I've loaded into GHCI.

From the names of the functions is not obvious to me which one I should be using; I'm sure it exists, and want to see a list of type signatures of the functions available to me. I don't know how to do this.

  • I can get a list of all the functions exported by the library by typing the module name and using tab-completing in GHCI.
  • Hoogle is useless to me, because the library in question isn't covered. Hoogle-style of searching would be useful, though.
  • I know of GHCI's :t, but it only seems to work for a single function, and I don't want to do this for every single function that is being exported by the library.
  • Running grep -R :: ./* or similar over the source directory may omit functions without explicit type signatures.
  • The library has Haddock documentation, but it has around 1000 functions spread out amongst dozens of submodules, and it's tedious and error prone to manually search them all.

I'm open to try any method, but obviously prefer what's simple, portable, and repeatable.

Is there a way to find the type signatures of all exported functions in a library? Or to find out which functions have a type signature that includes a certain type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人九事 2024-10-28 16:11:36

只需使用 :browse Module.Name 即可看到该模块导出的所有值:

> :browse Data.Tagged
newtype Tagged s b = Tagged {unTagged :: b}
asTaggedTypeOf :: s -> Tagged s b -> s
retag :: Tagged s b -> Tagged t b
tagSelf :: a -> Tagged a a
untag :: Tagged s b -> b
untagSelf :: Tagged a a -> a

just use :browse Module.Name and you'll see all the values exported by the module:

> :browse Data.Tagged
newtype Tagged s b = Tagged {unTagged :: b}
asTaggedTypeOf :: s -> Tagged s b -> s
retag :: Tagged s b -> Tagged t b
tagSelf :: a -> Tagged a a
untag :: Tagged s b -> b
untagSelf :: Tagged a a -> a
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文