【问题标题】:View non-exposed library functions while developing in Haskell在 Haskell 中开发时查看未公开的库函数
【发布时间】:2016-08-28 16:55:55
【问题描述】:

我犯了一个错误in another question 本来可以通过查看来解决的

:t myfunctionofinterest

对于我在库中使用的函数。

但是,当我在我的项目根目录中运行时

$ stack ghci

我的 Main.hs 有:

import MyLib

我的模块可以:

module MyLib {
  bunchOfFunctions -- but not myfunctionofinterest
} where

import SomeDB.ModuleThatExposes -- myfunctionofinterest

myfunc :: IO ()
myfunc = do
  myfunctionofinterest a b c -- place where I misuse myfunctionofinterest and could have used :t on it to see it had 3 args

我不能 :t myfunctionofinterest 在 main 中,因为它没有公开,Import MyLib.myfunctionofinterest 也没有明确 帮助,因为它是在导入中定义的。虽然我知道我可以公开它然后检查它,:a 进行编译,然后编辑库以再次隐藏它,有什么可以更快更直接地实现它吗?

这似乎是一种常见的模式。当您需要在开发过程中检查库中使用的东西的类型时,您会怎么做?

【问题讨论】:

  • import MyModule 如果 MyModuleexposed-modulesother-modules 在您的 cabal 文件中,则将起作用。

标签: haskell development-environment


【解决方案1】:

引用GHCi docs

:module 命令提供了一种方法来完成两件普通导入声明无法完成的事情:

  • :module 支持模块上的 * 修饰符,这会打开模块的完整顶级范围,而不仅仅是其导出。

附加的* 使GHCi 加载模块的字节码版本。这不会那么高效,但您可以访问未导出的绑定。

例子:

λ> :m *MyLib
λ> :t myfunctionofinterest

如果你得到

module 'MyLib' is not interpreted; try ':add *MyLib' first

您可能必须先执行:load(关于:add 的建议并不总是有效):

λ> :l *MyLib
λ> :m *MyLib
λ> :t myfunctionofinterest

【讨论】:

    猜你喜欢
    • 2015-05-27
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多