Hello! I have a Java application, which has a lot of GUI and one complex algorithm. I spent many months writing and debugging that algorithm, but it still has a lot of bugs. At the moment, I am thinking about implementing that algorithm in Haskell, while leaving the GUI in Java. I would like to know whether it is possible to write algorithmic (let's call them back-end) parts of a system in Haskell and user interface in Java? Can Haskell and Java parts of a system co-operate? Will such a hybrid system run on Windows and Linux? Are there any tutorials about this? Has someone already tried it? Thanks in advance Dmitri Pissarenko ----- Ende der weitergeleiteten Nachricht -----
On Fri, Jan 07, 2005 at 04:56:14PM +0100, Dmitri Pissarenko wrote:
I would like to know whether it is possible to write algorithmic (let's call them back-end) parts of a system in Haskell and user interface in Java?
If all else fails, you can "simply" split the program in two separate, communicating processes. Best regards, Tomasz
Dmitri Pissarenko wrote:
I would like to know whether it is possible to write algorithmic (let's call them back-end) parts of a system in Haskell and user interface in Java?
You could probably use the "foreign export" feature of the Haskell Foreign Function Interface [1] to make your Haskell function(s) callable from C, and then write a Java Native Interface [2] wrapper in C. /Bjorn [1] http://www.cse.unsw.edu.au/~chak/haskell/ffi/ [2] http://java.sun.com/docs/books/tutorial/native1.1/
On Sat, 08 Jan 2005 00:59:10 +0100, Bjorn Bringert <d00bring@dtek.chalmers.se> wrote:
You could probably use the "foreign export" feature of the Haskell Foreign Function Interface [1] to make your Haskell function(s) callable from C, and then write a Java Native Interface [2] wrapper in C.
I have found it impossible to call Haskell functions from Java using this approach, because Java needs foreign code to be compiled as a shared library, and GHC, on Linux at least, can't do that as far as I know. On the other hand a similar approach works well if you want to call Java methods from a Haskell program. I haven't tried it with Swing, but I made it work with JDBC a while ago. Here's an example, calling toString() on a Java Object: In Haskell: import Foreign type JObject = StablePtr () foreign import ccall toString :: JObject -> IO JObject and in C: #include <jni.h> jobject toString(jobject obj) { jclass clazz = (*env)->GetObjectClass(env, obj); jmethodID m = (*env)->GetMethodID(env, clazz, "toString", "()Ljava/lang/String;"); return (*env)->CallObjectMethod(env, obj, m); } Of course, there's more work to do: you need to start a JVM from your Haskell program; you need a Java Object in the first place; and if you want to see the string in Haskell, you have to unmarshall it using JNI and FFI, and so on ... P.S. Perhaps this discussion should move to the FFI list or haskell-cafe.
In article <20050107165614.o2eckk08owk048sw@confixx.p15142389.pureserver.info>, Dmitri Pissarenko <mailing-lists@dapissarenko.com> wrote:
Can Haskell and Java parts of a system co-operate?
See my JVM-Bridge, <https://sourceforge.net/projects/jvm-bridge/> -- Ashley Yakeley, Seattle WA
participants (5)
-
Ashley Yakeley -
Ben Horsfall -
Bjorn Bringert -
Dmitri Pissarenko -
Tomasz Zielonka