Reputation: 694
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. )
Upvotes: 7
Views: 1538
Reputation: 22721
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.
Upvotes: 1
Reputation: 9676
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.
Upvotes: 1
Reputation: 59983
The easy (but clumsy) way:
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.
Upvotes: 4