在Haskell中进行开发时查看非公开的库函数

Mit*_*ops 7 haskell development-environment

在另一个可以通过查看解决的问题上犯了一个错误

:t myfunctionofinterest
Run Code Online (Sandbox Code Playgroud)

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

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

$ stack ghci
Run Code Online (Sandbox Code Playgroud)

我的Main.hs有:

import MyLib
Run Code Online (Sandbox Code Playgroud)

我的模块做了:

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
Run Code Online (Sandbox Code Playgroud)

我不能:t在主要的myfunctionofinterest,因为它没有暴露,也没有Import MyLib.myfunctionofinterest明确的帮助,因为它是在导入中定义的东西.虽然我知道我可以暴露它然后检查它,:a编译,然后编辑lib再次隐藏它,有没有什么允许更快,更直接?

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

chi*_*chi 6

引用GHCi文档:

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

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

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

例:

?> :m *MyLib
?> :t myfunctionofinterest
Run Code Online (Sandbox Code Playgroud)

如果你得到

module 'MyLib' is not interpreted; try ':add *MyLib' first
Run Code Online (Sandbox Code Playgroud)

你可能必须先做:load(关于:add并不总是这样做的建议):

?> :l *MyLib
?> :m *MyLib
?> :t myfunctionofinterest
Run Code Online (Sandbox Code Playgroud)