Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run my haskell functions through Java

Tags:

java

haskell

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. )

like image 953
BinRoot Avatar asked Feb 14 '11 03:02

BinRoot


2 Answers

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.

like image 99
Anon. Avatar answered Oct 19 '22 23:10

Anon.


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.

like image 28
YasirA Avatar answered Oct 20 '22 00:10

YasirA