获取 :type-at 信息以获取 ghci 中的一长串模块

Getting :type-at information for a long list of modules in ghci

我有兴趣在 GHCI 中获取 :type-at 命令的输出以获取一长串模块。如果我手动执行 :type-at MyFile.hs M N M P,它工作正常;但是,对于这么多模块,我宁愿有一种方法可以自动执行查找该信息并将其存储到文件的过程。

有吗 a) 一种将 ghci 与输入文件一起使用的方法,输入文件告诉它要处理的所有命令,或者 b) 一种定义宏的方法,让我循环遍历值列表并将 :type-at 命令应用于所有这些值?

谢谢!

Is there a) a way to use ghci with an input file which tells it all the commands to process

有。您可以定义自定义 :source 命令,如下所示:

> :def source readFile
> let x = length "hello"
> :source GHCiTest.txt
x :: Int
5
5
x :: Int        -- Defined at <interactive>:6:5
hello

在上面的例子中,GHCiTest.txt包含了下面的GHCi命令,运行由:source一个接一个:

:t x
print x
x
:i x
putStrLn "hello"

或者,您可以使用自定义 .ghci 文件启动 GHCi,该文件在启动时自动 :sourced。