>Sigbjorn writes:
>Shane Stephens <[EMAIL PROTECTED]> writes:
>>..
>> What I want to know is - what would be the best way to run a haskell
>> function as a method in a Java class? (And how would I do this...)
>
>an alltogether Fine Idea this - the Java Native Interface (JNI) would
>be one way to go, accessing Haskell code via a native method.
Yes, but the direct solution depends on Haskell being callable from the
outside world. Unless the HaskellDirect docs have already been updated,
Shane might want to look at
"Calling hell from heaven and heaven from hell"
http://research.microsoft.com/Users/simonpj/#comserve
for a discussion of some of the issues involved.
>Wrapping the Haskell code up inside a COM component is another way
>(ok, I'm partially showing my colours here :) Employing CORBA is
>yet another.
Java->COM->Haskell is probably closer to being implemented than
Java->CORBA->Haskell? Currently, this would still be specific to
Microsoft platforms because the Java->COM part isn't standard, but it
might be an acceptable interim solution if you only want to play with
your ideas on a Windows system.
>Claus Reinke has done quite a bit of work on integrating Haskell
>with Java through the JNI, see http://www.cs.nott.ac.uk/~czr/JNI/
>I might be wrong about this, but the emphasis is there to use Java
>from Haskell, and not the other way around.
You are right about the emphasis. There is an indirect way to use a
Haskell->JNI->Java connection for calling Haskell from Java (the York
group described a similar approach for calling Haskell from C using
GreenCard
http://www.cs.york.ac.uk/fp/nhc13/CcallingHaskell.html ),
but with the FFI for GHC and Hugs relatively close to implementation, I
haven't explore that option yet.
>In any case, there's bound to be lots of useful info/code in there to
>either build on or use.
I hope so (although the web page should have more of the references
given in the paper). There have been quite a lot of "rearrangements"
regarding Hugs and GHC recently, and I haven't been unaffected by this.
Basically, I haven't been able to work on the software this year, i.e.,
the state is still very much as described in
"Towards a Haskell/Java connection"
Implementation of Functional Languages, IFL'98, London, September 1998
(the post-workshop proceedings have still not appeared, but you can
contact me if you want a preprint of the paper),
which is not bad, but not nearly as good as I would like it to be.
Fortunately, noone has complained yet, and I have a personal interest to
continue the work. I recall only two problems with Haskell/JNI itself:
- no finalizers for JNI object references (no real problem thanks to
GreenCard, but there were some unclear points in the JNI spec; will
add them as soon as I get back to the software)
- some minor, but annoying incompatibilities between GreenCard for
Hugs and for GHC (I focussed on Hugs, but I think Sigbjorn did
some more work on GreenCard for GHC before retiring from his FFI
developer role, so perhaps I should look at this again..)
So you should be able to use Haskell/JNI for doing Java graphics from
Hugs if you don't need callbacks (it would take some more effort to get
around the current callback problem, or some patience until the problem
is solved properly).
The real problem is that Java facilities never come in small pieces
(even the 2D API documentation has quite a few pages, lots of methods
and dependencies..). The last thing I started to work on was thus a way
to generate the necessary glue code for using a Java class via
Haskell/JNI automatically from the class file (a kind of GreenCard for
Java to make calling Java from Haskell via Haskell/JNI more
convenient:-). A base version of this didn't seem difficult, but I have
yet to find the time to continue working on it..
In brief, we agree on the idea, and some of what we want is already
there, but it will take some more time before the various parts (Haskell
FFI, HaskellDirect for GHC/Hugs, Haskell/JNI, etc.) work together to
make interoperation between Haskell and Java convenient for programmers.
Encouragement from potential users is always welcome.
Claus
PS. Since the question came on a ghc list (why bugs?-), I gave GHC or
Hugs specific answers. If the question was about Haskell and Java in
general, David Wakeling's work is also worth looking at, even though
he didn't focus on cross-language calls:
http://www.dcs.exeter.ac.uk/~david/research/java.htm