开发者

How can I run my haskell functions through Java

开发者 https://www.devze.com 2023-02-10 12:33 出处:网络
Lets say I have a haskell function add in math.hs How can I run the add function through a Java program and store the output as a variable?

Lets say I have a haskell function add in math.hs

How can I run the add function through a Java program and store the output as a variable?

Maybe something like the following:

public int runHaskell(String haskellFile) {
    int output;
    //run add function from file 'math.hs' and store result to output
    return output;
}

( If required I also have access to the object file: math.开发者_运维百科o and the interpreter file math.hi as well as the executable main.exe. )


The easy (but clumsy) way:

Runtime.exec()

Then you can listen to the output of the Haskell program, and then parse it for the result.

Alternatively, you can write a small wrapper for JNI that calls directly into your Haskell stuff.


You could use some of RPC frameworks, for example, Apache Thrift, which supports C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, Smalltalk, and OCaml.

There's also BERT-RPC client and server library for Haskell, but I'm not sure a Java port exists.


This might help: http://www.haskell.org/haskellwiki/Applications_and_libraries/Interfacing_other_languages. There is also Jaskell which might be able to run your entire source code under the JVM, allowing you to easily interface.

0

精彩评论

暂无评论...
验证码 换一张
取 消