相关疑难解决方法(0)

尝试为 C 导出 Haskell 库

作为将 Haskell 程序导出为 C 库的第一步,我复制了Haskell FFI 指南中的示例代码,但无法编译。我有foo.hs

module Foo where
foreign export ccall foo :: Int -> IO Int

foo :: Int -> IO Int
foo n = return (length (f n))

f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))
Run Code Online (Sandbox Code Playgroud)

这成功编译到foo_stub.hfoo_stub.o。这是foo_stub.h

#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt foo(HsInt a1);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)

但后来我的 C 程序没有编译:

#include "foo_stub.h"
main() { …
Run Code Online (Sandbox Code Playgroud)

c haskell

1
推荐指数
1
解决办法
569
查看次数

标签 统计

c ×1

haskell ×1