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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With