- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
来自Haskell Wiki page about calling Haskell function from C ,我正在尝试重现一个很好的简短示例,它归结为编译一些使用 C FFI 和命令行选项的 Haskell 代码,例如:
ghc -c -O Safe.hs
需要注意的一点是,在 Haskell Wiki 页面中,使用的编译器选项实际上是 -c
(小写),这不会生成中间 C 代码,所以这可能是一个拼写错误.
但是,正如我在尝试使用 -C
选项(记录为发出中间 C 代码的选项)进行编译时发现的那样,除非您在“未注册模式”下构建 GHC,否则这是不可用的基本上放弃了 GHC 的 native 代码生成器,只留下一个非常基本的 C 代码生成器(用于这些 FFI 示例的)和高度优化的基于 LLVM 的代码生成器。
事实上,from some documentation about GHC ,它建议您只能在未注册模式下使用-C
选项。
为了生成中间 C 代码(通过 -C
选项),您必须在未注册模式下构建 GHC 是真的吗?
如果这是真的,这是否意味着您几乎在任何情况下都不能按照这些说明从 C 代码调用 Haskell 代码(因为在未注册模式下构建通常是不可取的并且非常罕见)?
在我的例子中,我实际上有一个 Python 库和一些项目限制,这些限制意味着代码必须可以从 Python 调用,但是通过使用 Haskell 编写大量代码并使用 Haskell 函数可以大大受益。
我的目标是为 Python 创建一个扩展模块,使用带有 C 源代码的 Cython 可以很容易地做到这一点。因此,如果我可以创建 Haskell-from-C 源代码并将其编译为一个库,那么从 Python 调用它将会非常容易。然后我可以担心如何自动生成包装器代码。
但是如果它需要这种非常专业的构建 GHC 的方法,那么它对以后需要使用它的任何人都没有用,因为他们可能没有那种专门的构建并且不想大惊小怪.
这样一个简单的 FFI 功能(C 代码生成部分)似乎应该在任何 Haskell 编译器的最普通版本中“正常工作”,至少对我来说是这样。
最佳答案
如 Wiki 页面所述,您不需要未注册的 GHC 即可将 Haskell 函数导出到 C。这里有很多具体问题,我会一一解答。
From the Haskell Wiki page about calling Haskell function from C, there is a nice short example that I am trying to reproduce, which boils down to compiling some Haskell code that uses the C FFI with command line options such as:
ghc -c -O Safe.hs
One point of note is that in the Haskell Wiki page, the compiler option used is actually -c (lower case) and this does not generate the intermediate C code, so it is likely a typo.
这不是打字错误。 -c
表示“编译为对象 (.o
) 文件”,而不是默认的“编译为可执行文件”。 (选项名称与 C 编译器中相同选项的名称匹配,这就是它没有特别意义的原因。)
However, as I discovered when trying to compile with the -C option (the option that is documented as emitting intermediate C code), this is unavailable unless you build GHC in "unregisterised mode" which essentially drops GHC's native code generator and leaves only a very basic C code generator (what is used for these FFI examples) and the more highly optimized LLVM-based code generator.
In fact, from some documentation about GHC, it suggests that you can only use the -C option in unregisterised mode.
Is it true that you must build GHC in unregisterised mode in order to generate intermediate C code (via the -C option)?
是的,因为只有未注册的编译器才能通过中间 C 代码进行编译。注册编译器(因此得名)使用的 GHC 调用约定(将各种全局变量固定到寄存器)根本无法用 C 语言表达。并且,特定的 GHC 构建是生成注册代码还是未注册代码是在该 GHC 构建的编译时做出的决定。
If this is true, doesn't it imply that you can't follow these instructions to call Haskell code from C code in almost any situation (since building in unregisterised mode is generally undesirable and very uncommon)?
不,因为您也可以从 C 代码调用由注册编译器构建的 Haskell 代码。 C 的一个很好的特性是它有一个相对标准的(每个平台)ABI,因此任何语言的编译器都可以生成与 C 目标文件二进制兼容的目标文件,而根本不需要调用主机 C 编译器。
In my case, I have actually a Python library and some project constraints that imply the code must be callable from Python, but which can benefit greatly from writing a lot of it in Haskell and using Haskell functions.
My goal is to create an extension module for Python, which is very easy to do using Cython with C source. So if I can create the Haskell-from-C source and compile it to a library, it will be pretty easy to call from Python. Then I can worry about how to generate that wrapper code automatically.
But if it requires this very specialized way of building GHC, it won't be useful to anyone who needs to work with it later, because they probably won't have that specialized build and won't want to fuss with it.
Such a simple FFI capability (the C code generation part) seems like something that should "just work" in the most vanilla of builds of any Haskell compiler, at least to me.
是的,它只适用于任何 GHC 版本。它实际上并没有作为中间形式通过 C; GHC 的输出是一个目标文件。
关于c - 在正常情况下,未注册模式要求是否会阻止 Haskell 的基本 FFI 示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30540933/
我刚开始学习JSP技术,遇到了瓶颈。 如何从 JSP 声明 block ? 这不起作用: ... 服务器说没有“out”。 U: 我确实知道如何使用返回字符串的方法重写代码,但是有没有办法在 ?
在一个字段中,我想设置一个具有自定义过滤器的自定义分析器-着眼于词干-因此,“闪存卡”和“闪存卡”的词根相同,因此返回的结果相同 当我运行以下查询时,我的命中率很高,但是“闪存卡”和“闪存卡”各自返回
快速提问。 我有一个通过 PInvoke 使用 native DLL 的应用程序,这个 DLL 可能会调用 PostQuitMessage()。 如何避免? (因为我的应用程序不应该关闭) 我试过 A
一些给定的 HTML 文章,例如: Content 与一些基本的 Jquery 结合使用,例如: $(".some_
我正在构建一个灯箱相册。当第一个图像加载时,CSS 转换起作用。当加载后的每个图像都没有。任何想法为什么?加载第一张之后的照片,但没有过渡。 Image.prototype.load = functi
这个问题在这里已经有了答案: Disable recent tasks button on Android 5.0 (2 个答案) 关闭 2 年前。 我知道这个问题之前在这里被问过 Android
我是 Objective-C 的新手,我只是想弄清楚我是否可以使用 block 或选择器作为 UIAlertView 的 UIAlertViewDelegate 参数 - 哪个更合适? 我已经尝试了以
我是 Linux (UNIX) 套接字下套接字编程的新手。我在 Internet 上找到了以下代码,用于为每个连接生成一个线程的 tcp 服务器。但是它不起作用。accept() 函数立即返回,不等待
recv()库函数手册页提到: It returns the number of bytes received. It normally returns any data available, up
我有一个用于其他项目的共享 ts 库。在这个库中有被同一个库的其他资源使用的资源。该库的结构分为 components/*、interfaces/*、services/* 等目录。在每个目录的根目录中
我想在同一行中一个接一个地显示我的 ListView ,但 ListView 显示每个新行中的每个项目。我怎样才能防止换行显示。以便它显示为段落 ListView.builder( shr
我有一个包含数千行的表格。 import React from "react" import { useSelector } from "react-redux"; import { useEffec
假设我通常希望收到关于代码中不完整模式的警告,但有时我知道某个函数的模式不完整,我知道这很好。 是still true GHC 的警告粒度是每个模块的,并且没有办法更改有关特定功能或定义的警告? 最佳
我的网络应用程序发送浏览器通知,我知道如何检查通知的浏览器权限,以及如果未授予权限,如何请求权限。 但是,即使用户授予我的站点发送通知的权限,她可能仍然无法收到通知,因为它们 might be dis
我有 Xcode 3.2.1,并且喜欢使用它,但是当我编辑文本中带有超链接的文件时(例如,带有引用的注释:# see http://example.com)Xcode 将文本变成可点击的超链接。尝试编
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许在 Stack Overflow 上提出有关通用计算硬件和软件的问题。您可以编辑问题,使其成为
我有一个在 MY_Controller 中运行的 acl。如果权限被拒绝,那么此刻,我只是执行 redirect('denied') - 这是一个非常基本的 Controller ,它加载一个非常基本
我一直很好奇尝试从 Chrome 切换到 Firefox Quantum,但是对于 Web 开发遇到了一个我无法轻松解决的主要障碍——它正在缓存我的本地主机文件,因此当我尝试在本地主机加载各种 emb
这真的让我很兴奋!在任何时候,我都会参与多个项目。当我退出Xcode时,下次打开Xcode时,我前一天的所有项目都会自动一一打开。 经常我最终编辑错误的文件,AHHHHHHHHHHH!我可以阻止这种行
我的Wiki上有500个左右的Spambot和大约5个实际注册用户。我已经使用nuke删除了他们的页面,但是他们一直在重新发布。我已经使用reCaptcha控制了spambot的注册。现在,我只需要一
我是一名优秀的程序员,十分优秀!