从 Python 调用 Haskell 函数 [英] Calling Haskell functions from Python
问题描述
我想使用 Python 中的一些 Haskell 库(例如 Darcs、Pandoc),但在 Python 中似乎没有直接与 Haskell 的外部函数接口.有没有办法做到这一点?
I want to use some Haskell libraries (e.g. Darcs, Pandoc) from Python, but it seems there’s no direct foreign function interface to Haskell in Python. Is there any way to do that?
推荐答案
推荐答案
另一种方法是编写标准的 IPC 接口,在 darcs 和 pandoc 的情况下,只需将它们作为普通可执行文件调用并解析它们的输出可能是可行的方法.
Another approach would be to write a standard IPC interface, in the case of darcs and pandoc just calling them as vanilla executables and parsing their output might be the way to go.
关于在 Haskell 端自动生成枯燥、重复、FFI 和编组代码,我推荐 c2hs,它允许您基于现有的 C 接口自动生成很多.python 可能也有类似的东西.
As to automating the generation of boring, repetitive, FFI and marshalling code on the Haskell side, I'd recommend c2hs, which allows you to auto-generate a lot based on an existing C interface. There's probably similar things for python.
唉,据我所知,SWIG 从未为 Haskell 实现,大概是因为它迎合了不太严格类型的语言.
SWIG, alas, has, to the best of my knowledge, never been implemented for Haskell, presumably because it caters to less strictly-typed languages.
这篇关于从 Python 调用 Haskell 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!