Interfacing Java/Haskell

Hi all, I am rather new to the café, so I just hope my question fits in. Does anyone have experience with integrating Haskell and Java? I have done some searching, finding a lot of pointers but hardly anything in terms of evaluation, successes, or caveats.
From what I see Frege looks promising, arguably not haskell I suppose, but does it work? Other projects I have seen appear to have reached a stand-still for ages.
The background for the question is that I will contribute some control algorithms based on machine learning or AI in a larger project. It would save me a lot of time if I could write in Haskell, but only assuming that interfacing with Java afterwards is trivial compared to writing everything in java in the first place. I am, perhaps, particularly worried that a Haskell-lookalike for JVM might be unable to optimise properly, like not being lazy. Any advice? TIA -- :-- Hans Georg

(oops, forgot to reply all) if you're on the jvm already why not consider clojure? it lacks static typing, but S expressions can stand in for haskell types if you really need them to. otherwise you'll have to do some fancy JNI calls and worry about calling haskell from C, like this http://www.haskell.org/haskellwiki/Calling_Haskell_from_C On Thu, May 9, 2013 at 11:04 AM, Hans Georg Schaathun < georg+haskell@schaathun.net> wrote:
Hi all,
I am rather new to the café, so I just hope my question fits in.
Does anyone have experience with integrating Haskell and Java? I have done some searching, finding a lot of pointers but hardly anything in terms of evaluation, successes, or caveats.
From what I see Frege looks promising, arguably not haskell I suppose, but does it work? Other projects I have seen appear to have reached a stand-still for ages.
The background for the question is that I will contribute some control algorithms based on machine learning or AI in a larger project. It would save me a lot of time if I could write in Haskell, but only assuming that interfacing with Java afterwards is trivial compared to writing everything in java in the first place. I am, perhaps, particularly worried that a Haskell-lookalike for JVM might be unable to optimise properly, like not being lazy. Any advice?
TIA -- :-- Hans Georg
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hans Georg Schaathun
Does anyone have experience with integrating Haskell and Java? I have done some searching, finding a lot of pointers but hardly anything in terms of evaluation, successes, or caveats.
From what I see Frege looks promising, arguably not haskell I suppose, but does it work? Other projects I have seen appear to have reached a stand-still for ages.
EclipseFP uses Haskell and Java processes talking to each other in JSON. That's the route which successful multi-lingual projects generally seem to go.

Hello, I've had some success with the Thrift library (http://thrift.apache.org/). See this blog post (http://mortenib.wordpress.com/2009/10/29/thrift-and-haskell/) for a basic tutorial on getting started. My project was interfacing a haskell library of machine learning algorithms (which I wrote) with a large Java application I was familiar with but didn't write. So this may be what you're looking for. Thrift interfaces language X with language Y with a sort of RPC paradigm: you specify the names and types of the possible calls and returns, and Thrift uses this file to generate serialization and transport code for whatever languages you name. You then add this code to the project on each side and things pretty much just work. On Thu, May 09, 2013 at 04:04:19PM +0100, Hans Georg Schaathun wrote:
Hi all,
I am rather new to the café, so I just hope my question fits in.
Does anyone have experience with integrating Haskell and Java? I have done some searching, finding a lot of pointers but hardly anything in terms of evaluation, successes, or caveats.
From what I see Frege looks promising, arguably not haskell I suppose, but does it work? Other projects I have seen appear to have reached a stand-still for ages.
The background for the question is that I will contribute some control algorithms based on machine learning or AI in a larger project. It would save me a lot of time if I could write in Haskell, but only assuming that interfacing with Java afterwards is trivial compared to writing everything in java in the first place. I am, perhaps, particularly worried that a Haskell-lookalike for JVM might be unable to optimise properly, like not being lazy. Any advice?
TIA -- :-- Hans Georg
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thank you very much to everyone who responded on java integration. I have a lot of work to do before I can conclude, but I will give a quick summary just in case there is some general interest. The most common approach appears to be a network interface between separate java and haskell processes. Both JSON and thrift appear to tools to help doing that. That sounds like a good idea if effort is taken properly to plan out the system architecture. In my case, it would probably lead me to write more code in haskell than I had originally planned (for good or for bad). One poster pointed to neurocyte's library of JNI bindings. That's definately something I will look into. At first sight, it looks much easier to get into than I had feared. The most popular proposal was, nevertheless, to use other languages, in particular hybrid languages like scala. In my opinion, that only solves a minor part of the problem. In my opinion, the chief virtue of a pure language like haskell is its simplicity. Yet, I must admit, that option was always on my list. Familiar with python, jython is a serious option, although I would prefer strong and static type checking. Thanks again, everyone :-- George On Thu, May 09, 2013 at 11:48:09AM -0700, Dominic Espinosa wrote:
Hello,
I've had some success with the Thrift library (http://thrift.apache.org/). See this blog post (http://mortenib.wordpress.com/2009/10/29/thrift-and-haskell/) for a basic tutorial on getting started. My project was interfacing a haskell library of machine learning algorithms (which I wrote) with a large Java application I was familiar with but didn't write. So this may be what you're looking for.
Thrift interfaces language X with language Y with a sort of RPC paradigm: you specify the names and types of the possible calls and returns, and Thrift uses this file to generate serialization and transport code for whatever languages you name. You then add this code to the project on each side and things pretty much just work.
On Thu, May 09, 2013 at 04:04:19PM +0100, Hans Georg Schaathun wrote:
Hi all,
I am rather new to the café, so I just hope my question fits in.
Does anyone have experience with integrating Haskell and Java? I have done some searching, finding a lot of pointers but hardly anything in terms of evaluation, successes, or caveats.
From what I see Frege looks promising, arguably not haskell I suppose, but does it work? Other projects I have seen appear to have reached a stand-still for ages.
The background for the question is that I will contribute some control algorithms based on machine learning or AI in a larger project. It would save me a lot of time if I could write in Haskell, but only assuming that interfacing with Java afterwards is trivial compared to writing everything in java in the first place. I am, perhaps, particularly worried that a Haskell-lookalike for JVM might be unable to optimise properly, like not being lazy. Any advice?
TIA -- :-- Hans Georg
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- :-- Hans Georg

For a simple interchange format, you might also look at MSGPACK; the bindings are nice and the format is simple. I used it for call-haskell-from-anything (https://github.com/nh2/call-haskell-from-anything), a concept with which you can call Haskell code from any language that supports loading shared object files. On Thu 16 May 2013 02:07:41 SGT, Hans Georg Schaathun wrote:
The most common approach appears to be a network interface between separate java and haskell processes. Both JSON and thrift appear to tools to help doing that.

On 2013-05-09 17:04, Hans Georg Schaathun wrote:
Does anyone have experience with integrating Haskell and Java? I have done some searching, finding a lot of pointers but hardly anything in terms of evaluation, successes, or caveats.
From what I see Frege looks promising, arguably not haskell I suppose, but does it work? Other projects I have seen appear to have reached a stand-still for ages.
The background for the question is that I will contribute some control algorithms based on machine learning or AI in a larger project. It would save me a lot of time if I could write in Haskell, but only assuming that interfacing with Java afterwards is trivial compared to writing everything in java in the first place. I am, perhaps, particularly worried that a Haskell-lookalike for JVM might be unable to optimise properly, like not being lazy. Any advice?
I have successfully written Java/Haskell programs using the Java Native Interface. You can find my JNI to Haskell binding library at https://github.com/neurocyte/foreign-jni. I am primarily using it to write Android Apps with Haskell, but I’ve done a little testing with the standard JVM and it works fine. There is a bare bones demonstration of a Java/Haskell application at https://github.com/neurocyte/android-haskell-activity. That is for Android, but the basic principals are the same for plain JVM integration. I am currently working on a tool to generate full (or at least fully usable) Haskell bindings to Java libraries (using foreign-jni), including being able to implement Java callback interfaces in Haskell. That is still a work in progress though and I have not yet published it to github. The intent is to generate a full set of bindings to the Android API, but it is pretty generic and should work for any Java API. -- CJ van den Berg mailto:cj@vdbonline.com xmpp:neurocyte@gmail.com

CJ van den Berg
I have successfully written Java/Haskell programs using the Java Native Interface. You can find my JNI to Haskell binding library at https://github.com/neurocyte/foreign-jni. I am primarily using it to write Android Apps with Haskell,
Just out of curiosity, have you got any complete apps that you built that way? Are they in the Google Store? Manuel

I'm also interested in seeing this. Have you ported the Haskell runtime to Android? It seems like this should be able to be done, and through the JNI it seems like you should be able to get the system API (albeit, ugly). However, I'd be really happy to see this setup if you were willing to put it up somewhere so I could hack on it too. Kris On Mon, May 27, 2013 at 8:07 PM, Manuel M T Chakravarty < chak@cse.unsw.edu.au> wrote:
CJ van den Berg
: I have successfully written Java/Haskell programs using the Java Native Interface. You can find my JNI to Haskell binding library at https://github.com/neurocyte/foreign-jni. I am primarily using it to write Android Apps with Haskell,
Just out of curiosity, have you got any complete apps that you built that way? Are they in the Google Store?
Manuel
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I guess you can't really go from native -> framework code like this, so
this would really make sense only for native methods that are self
contained. Is this right? It seems like this would imply that you can
only write parts of an app's computation in Haskell, not the whole thing.
But maybe I'm wrong. I have seen people that write apps in native /
managed code integrating in a reasonable way, but it's very ugly afaik.
Kris
On Tue, May 28, 2013 at 9:35 AM, Kristopher Micinski wrote: I'm also interested in seeing this. Have you ported the Haskell runtime to Android? It seems like this should
be able to be done, and through the JNI it seems like you should be able to
get the system API (albeit, ugly). However, I'd be really happy to see this setup if you were willing to put
it up somewhere so I could hack on it too. Kris On Mon, May 27, 2013 at 8:07 PM, Manuel M T Chakravarty <
chak@cse.unsw.edu.au> wrote: CJ van den Berg I have successfully written Java/Haskell programs using the Java
Native Interface. You can find my JNI to Haskell binding library at
https://github.com/neurocyte/foreign-jni. I am primarily using it to
write Android Apps with Haskell, Just out of curiosity, have you got any complete apps that you built that
way? Are they in the Google Store? Manuel _______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

No, you can go both ways. You can call Haskell from Java and Java from Haskell. Write Android Apps in Haskell will of course be just the same as writing Android Apps in Java. That’s just the price you pay for having full API access. There is of course nothing preventing someone from creating more idiomatic Haskell GUI libraries for Android on top of the API bindings. On 2013-05-28 15:37, Kristopher Micinski wrote:
I guess you can't really go from native -> framework code like this, so this would really make sense only for native methods that are self contained. Is this right? It seems like this would imply that you can only write parts of an app's computation in Haskell, not the whole thing. But maybe I'm wrong. I have seen people that write apps in native / managed code integrating in a reasonable way, but it's very ugly afaik.
Kris
On Tue, May 28, 2013 at 9:35 AM, Kristopher Micinski
mailto:krismicinski@gmail.com> wrote: I'm also interested in seeing this.
Have you ported the Haskell runtime to Android? It seems like this should be able to be done, and through the JNI it seems like you should be able to get the system API (albeit, ugly).
However, I'd be really happy to see this setup if you were willing to put it up somewhere so I could hack on it too.
Kris
On Mon, May 27, 2013 at 8:07 PM, Manuel M T Chakravarty
mailto:chak@cse.unsw.edu.au> wrote: CJ van den Berg
mailto:cj@vdbonline.com>: > I have successfully written Java/Haskell programs using the Java > Native Interface. You can find my JNI to Haskell binding library at > https://github.com/neurocyte/foreign-jni. I am primarily using it to > write Android Apps with Haskell, Just out of curiosity, have you got any complete apps that you built that way? Are they in the Google Store?
Manuel
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- CJ van den Berg mailto:cj@vdbonline.com xmpp:neurocyte@gmail.com

Awesome!
I was hoping that someone would do this, and I'd be really happy to see
what could be done here.
This is the big crutch of using Haskell on Android is obviously that the
API sort of sucks for Haskell...
Kris
On Tue, May 28, 2013 at 2:01 PM, CJ van den Berg
No, you can go both ways. You can call Haskell from Java and Java from Haskell.
Write Android Apps in Haskell will of course be just the same as writing Android Apps in Java. That’s just the price you pay for having full API access. There is of course nothing preventing someone from creating more idiomatic Haskell GUI libraries for Android on top of the API bindings.
On 2013-05-28 15:37, Kristopher Micinski wrote:
I guess you can't really go from native -> framework code like this, so this would really make sense only for native methods that are self contained. Is this right? It seems like this would imply that you can only write parts of an app's computation in Haskell, not the whole thing. But maybe I'm wrong. I have seen people that write apps in native / managed code integrating in a reasonable way, but it's very ugly afaik.
Kris
On Tue, May 28, 2013 at 9:35 AM, Kristopher Micinski
mailto:krismicinski@gmail.com> wrote: I'm also interested in seeing this.
Have you ported the Haskell runtime to Android? It seems like this should be able to be done, and through the JNI it seems like you should be able to get the system API (albeit, ugly).
However, I'd be really happy to see this setup if you were willing to put it up somewhere so I could hack on it too.
Kris
On Mon, May 27, 2013 at 8:07 PM, Manuel M T Chakravarty
mailto:chak@cse.unsw.edu.au> wrote: CJ van den Berg
mailto:cj@vdbonline.com>: > I have successfully written Java/Haskell programs using the Java > Native Interface. You can find my JNI to Haskell binding library at > https://github.com/neurocyte/foreign-jni. I am primarily using it to > write Android Apps with Haskell, Just out of curiosity, have you got any complete apps that you built that way? Are they in the Google Store?
Manuel
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- CJ van den Berg
mailto:cj@vdbonline.com xmpp:neurocyte@gmail.com

The RTS was ported to Android, yes. But not by me. I just wrote ghc-android, which is just a build script to help people with setting up the somewhat complex cross-compiler build. IIRC Nathan Hüsken did most of the porting work. Everything you need should be on github. ghc-android and foreign-jni is pretty much it right now. Using the JNI is a bit ugly, yes. But I see it really as just a tool for writing more appealing API bindings, which is what I am working on now. On 2013-05-28 15:35, Kristopher Micinski wrote:
I'm also interested in seeing this.
Have you ported the Haskell runtime to Android? It seems like this should be able to be done, and through the JNI it seems like you should be able to get the system API (albeit, ugly).
However, I'd be really happy to see this setup if you were willing to put it up somewhere so I could hack on it too.
Kris
On Mon, May 27, 2013 at 8:07 PM, Manuel M T Chakravarty
mailto:chak@cse.unsw.edu.au> wrote: CJ van den Berg
mailto:cj@vdbonline.com>: > I have successfully written Java/Haskell programs using the Java > Native Interface. You can find my JNI to Haskell binding library at > https://github.com/neurocyte/foreign-jni. I am primarily using it to > write Android Apps with Haskell, Just out of curiosity, have you got any complete apps that you built that way? Are they in the Google Store?
Manuel
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- CJ van den Berg mailto:cj@vdbonline.com xmpp:neurocyte@gmail.com

On 2013-05-28 02:07, Manuel M T Chakravarty wrote:
CJ van den Berg
: I have successfully written Java/Haskell programs using the Java Native Interface. You can find my JNI to Haskell binding library at https://github.com/neurocyte/foreign-jni. I am primarily using it to write Android Apps with Haskell,
Just out of curiosity, have you got any complete apps that you built that way? Are they in the Google Store?
No. Nothing more than the demo app at this point and it is not in the Play Store. I hope to port some more interesting Haskell application once I have the full API bindings working. I am fairly short on extra time though at the moment. -- CJ van den Berg mailto:cj@vdbonline.com xmpp:neurocyte@gmail.com b
participants (8)
-
CJ van den Berg
-
Dan Mead
-
Dominic Espinosa
-
Hans Georg Schaathun
-
harry
-
Kristopher Micinski
-
Manuel M T Chakravarty
-
Niklas Hambüchen