如何从Python程序中调用OCaml函数?

时间:2021-05-20 20:44:51

I've got a large legacy program that is written in OCaml, and I'd like to be able to call some OCaml functions from my Python program.

我有一个用OCaml编写的大型遗留程序,我希望能够从我的Python程序中调用一些OCaml函数。

How can I do this the easiest way?

我怎样才能以最简单的方式做到这一点?

3 个解决方案

#1


8  

Directly, no. However, if you create a C API for your Ocaml library, you can call that API via. Python's ctypes module or similar. Likewise, if you expose a network service for your OCaml application, Python can call into that.

直接,没有。但是,如果为Ocaml库创建C API,则可以通过该API调用该API。 Python的ctypes模块或类似的。同样,如果您为您的OCaml应用程序公开网络服务,Python可以调用它。

#2


8  

You might find useful Pycaml, a Python-OCaml interface allowing to call OCaml functions from Python and vice versa.

您可能会发现有用的Pycaml,一个允许从Python调用OCaml函数的Python-OCaml接口,反之亦然。

Be sure to look for the 2011 or later version, which is based on a 2002 version.

请务必查找基于2002版本的2011或更高版本。

#3


4  

Pycaml is no more maintained: nowadays there is pyml and lymp to do that.

Pycaml不再被维护:现在有pyml和lymp这样做。

pyml: http://pyml.gforge.inria.fr lymp: https://github.com/dbousque/lymp

pyml:http://pyml.gforge.inria.fr lymp:https://github.com/dbousque/lymp

Both of them are available in opam (opam install pyml lymp). I have not tried them yet, but since I know the author of pyml is very competent, I would bet on that one.

它们都有opam(opam install pyml lymp)。我还没有尝试过,但是因为我知道pyml的作者非​​常称职,所以我会打赌那个。

#1


8  

Directly, no. However, if you create a C API for your Ocaml library, you can call that API via. Python's ctypes module or similar. Likewise, if you expose a network service for your OCaml application, Python can call into that.

直接,没有。但是,如果为Ocaml库创建C API,则可以通过该API调用该API。 Python的ctypes模块或类似的。同样,如果您为您的OCaml应用程序公开网络服务,Python可以调用它。

#2


8  

You might find useful Pycaml, a Python-OCaml interface allowing to call OCaml functions from Python and vice versa.

您可能会发现有用的Pycaml,一个允许从Python调用OCaml函数的Python-OCaml接口,反之亦然。

Be sure to look for the 2011 or later version, which is based on a 2002 version.

请务必查找基于2002版本的2011或更高版本。

#3


4  

Pycaml is no more maintained: nowadays there is pyml and lymp to do that.

Pycaml不再被维护:现在有pyml和lymp这样做。

pyml: http://pyml.gforge.inria.fr lymp: https://github.com/dbousque/lymp

pyml:http://pyml.gforge.inria.fr lymp:https://github.com/dbousque/lymp

Both of them are available in opam (opam install pyml lymp). I have not tried them yet, but since I know the author of pyml is very competent, I would bet on that one.

它们都有opam(opam install pyml lymp)。我还没有尝试过,但是因为我知道pyml的作者非​​常称职,所以我会打赌那个。