需要一个使用 GHC 解析和类型检查 Haskell 的教程
我正在开发一个分析 Haskell 代码的项目。我决定使用 GHC 来解析源代码并推断类型,而不是编写自己的代码来执行此操作。现在,我正在努力阅读 Haddock 文档,但进展缓慢。有谁知道一个好的教程吗?
编辑:澄清一下,我不是在寻找像 hlint 这样的东西。我正在编写自己的工具来分析 Haskell 代码的运行时特征,所以就像我正在编写不同的 hlint。我正在寻找的基本上是 wiki 页面的扩展 GHC 作为库。
I'm working on a project for analyzing Haskell code. I decided to use GHC to parse the source and infer types rather than write my own code to do that. Right now, I'm slogging through the Haddock docs, but it's slow going. Does anyone know of a good tutorial?
EDIT: To clarify, I'm not looking for something like hlint. I'm writing my own tool to analyze the runtime characteristics of Haskell code, so it's like I'm writing a different hlint. What I'm looking for is basically an expansion of the wiki page GHC As a library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
啊!在以下位置找到了更好的文档入口点:
http://www.haskell.org /ghc/docs/latest/html/libraries/ghc-6.12.1/GHC.html
我更新了 wikipage 与此示例:
这里我们演示调用 parseModule、typecheckModule、desugarModule、getNamesInScope 和 getModuleGraph。这适用于 haskell 平台、ghc-6.12.1。
bug:libdir 是硬编码的。请参阅上面的 ghc 路径。
Ah! found a much better entry point into the docs at:
http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-6.12.1/GHC.html
I updated the wikipage with this example:
Here we demonstrate calling parseModule, typecheckModule, desugarModule, getNamesInScope, and getModuleGraph. This works for haskell-platform, ghc-6.12.1.
bugs: libdir is hardcoded. See ghc-paths above.
亚当,这是相当艰难的雪橇。自 2006 年推出以来,GHC API 的记录一直有些不足。我建议尝试找到一些使用 GHC API 编写的小应用程序。正确的提问地点可能是 GHC 用户邮件列表。
ghctags 就是这样一个程序,它随 GHC 源代码树一起提供。我写了最初的版本,但我不能推荐它——代码上有太多的足迹,我无法再遵循它。我能说的最多的是,虽然它很难理解,但它至少小并且难以理解——比所有 GHC 简单得多。
Adam, this is pretty tough sledding. Ever since its launch in 2006, the GHC API has been somewhat underdocumented. What I would recommend is to try to find some small applications that have been written using the GHC API. The right place to ask is probably the GHC users' mailing list.
One such program is
ghctags
, which ships with the GHC source tree. I wrote the original version, but I can't recommend it—there are so many footprints on the code that I can no longer follow it. The best I can say is that although it's hard to follow, it's at least small and hard to follow—much simpler than all of GHC.如果解析是最重要的事情,我推荐 haskell-src-exts。它解析所有的Haskell98,一大堆扩展,并且非常容易使用。
If parsing is the most important thing, I recommend haskell-src-exts. It parses all of Haskell98, a whole pile of extensions and is very easy to use.
Haskell wiki 和 GHC 文档可能包含您要查找的内容。您可能感兴趣的另一个工具是 hlint,用于检查语法和其他内容关于你的源代码。
The Haskell wiki and GHC documentation probably has what you are looking for if you search for the articles. Also a tool you might be interested in is hlint, for checking the syntax and other things about your source code.