haskell - inline-c 和 language-c-inline 有什么区别?

标签 haskell ghc template-haskell

我一直在简要研究 Haskell 的准引用库。这些库允许 Haskell 与其他语言集成。为了与 C 集成,似乎有两个具有相似功能的包:

  • inline-c
  • language-c-inline (使用 language-c-quote )

  • 由于我正在寻找自己的准引用库,因此我对设计选择、API 差异、性能等感兴趣。

    我知道的唯一区别是 language-c-quote支持 C 和 Objective-C,而 inline-c支持 C.

    你会如何区分这些包?有哪些根本区别?事实上,它们是否相似?

    最佳答案

    inline-c 's reddit announcement 中(不久)讨论的一些差异:

    How does this compare to language-c-inline?



    • In inline-c we have a very simple core library which is easily extensible with additional anti quoters. I wanted the core functionality to be very predictable, and leave fancier marshalling up to specific use cases. In language-c-inline the marshalling works with a mix of hard-coded rules and user-supplied Template Haskell functions.
    • We wanted to make the language to include the C code as simple as possible. The inline C is spliced with a quasi quoter and no Template Haskell functions. The inline C code specifies the Haskell variables to capture using anti-quoters, and the target types are all specified using C syntax. As I say in the blog post I cared quite a bit that this is the case, to have confidence that what you're getting in C is what you expect. Relatedly, only the anti-quoters are examined: the rest of the C code is not parsed and left verbatim, so we don't have to worry about eventual incompatibilities between the C compiler the user is using and the Haskell C parser that language-c-inline uses.
    • We're also making sure that the infrastructure and build process is smooth. The addTopDecl function is used to avoid having to populate tables at runtime like language-c-inline does, and I also employ various tricks to make sure that everything will work smoothly across builds. For example, the names of the generated C functions is based on the hash of the contents of the function itself. This is quite important to guarantee that repeated builds of the same file by cabal -- for example when compiling with profiling support -- result in the same C symbols being generated, while making sure that the the symbols are the same only if the C snippets in the module are the same.

      […]

    In short, the two libraries are very similar in spirit, but we coded inline-c to be better suited to our needs taking different design choices. Some of the advantages above could be easily ported to language-c-inline, especially the ones in the last point.



    announcement on fpcomplete还包含其他信息,但总而言之,是的,它们有些相似。

    关于haskell - inline-c 和 language-c-inline 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30478003/

    相关文章:

    haskell - 这个准引用表达式有错误吗?

    Haskell:我想我真的可以在这里使用类似 Lisp 的宏

    yesod - 使用 yesod 时如何查看特定文件生成的模板 haskell 代码

    haskell - 如何在 Haskell 中检查两个文件是否相等

    haskell - 实例声明中的非法类型签名

    arrays - Haskell 列表到数组

    pointers - 为什么带有多态 Ptr 的 `peek` 在与绑定(bind)一起使用时会返回 GHC.Prim.Any?

    haskell - 函数依赖中的模糊类型

    Haskell - 为树类型创建折叠函数

    haskell -::运算符语法在有界类型类的上下文中如何工作?