Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language ...
Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language (or generate bytecode) to access the Java class libraries when needed? Or Is there a way for a JVM language or bytecode to call Haskell when needed? -- -- Regards, KC
KC <kc1956@gmail.com> writes:
Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language (or generate bytecode) to access the Java class libraries when needed?
Or
Is there a way for a JVM language or bytecode to call Haskell when needed?
I'd be very interested to know the answer to this as well. Please let me know what you discover. John
KC <kc1956@gmail.com> writes:
Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language (or generate bytecode) to access the Java class libraries when needed?
I once did a small test to get this working. It's not that hard, but needs some work. It's fine for exposing a few functions though. Basically it's a 2-step process, eased by using a makefile or similar helper. You have to compile your haskell code into a shared object (.so on linux, .dll on windows), which includes the haskell runtime (rts). This library can be called from c. A small pitfall is that you first need to do a call to initialize the haskell runtime, and when you're done using it, close it. This is most easily just tied to your c/java program's main initialization functions. Java is able to load/use these shared libraries through JNI. Of course you lose your platform-independance, so if you want your java application to work on multiple platforms / OSses, you need to build shared objects for all of them. Last but not least: You have to export the haskell functions you want through FFI. Also, make sure they use raw data types such as CString, as that what C and java will give you and expect back. So basically you go Haskell FFI <-> C <-> Java JNI I'm sorry I cannot give you any links or code, because I'm in a bit of a hurry. But google and the ghc docs are your friend. Mathijs
Or
Is there a way for a JVM language or bytecode to call Haskell when needed?
You may want to have a look at my little HJVM project on Github ( https://github.com/JPMoresmau/HJVM). Promise, I'll put in on Hackage some day. Basically it provides FFI wrappers and some c code to be able to start a JVM and call Java methods, etc from Haskell. -- JP Moresmau http://jpmoresmau.blogspot.com/ On Tue, Nov 20, 2012 at 7:53 AM, Mathijs Kwik <mathijs@bluescreen303.nl>wrote:
KC <kc1956@gmail.com> writes:
Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language (or generate bytecode) to access the Java class libraries when needed?
I once did a small test to get this working. It's not that hard, but needs some work. It's fine for exposing a few functions though.
Basically it's a 2-step process, eased by using a makefile or similar helper.
You have to compile your haskell code into a shared object (.so on linux, .dll on windows), which includes the haskell runtime (rts).
This library can be called from c. A small pitfall is that you first need to do a call to initialize the haskell runtime, and when you're done using it, close it. This is most easily just tied to your c/java program's main initialization functions.
Java is able to load/use these shared libraries through JNI. Of course you lose your platform-independance, so if you want your java application to work on multiple platforms / OSses, you need to build shared objects for all of them.
Last but not least: You have to export the haskell functions you want through FFI. Also, make sure they use raw data types such as CString, as that what C and java will give you and expect back.
So basically you go Haskell FFI <-> C <-> Java JNI
I'm sorry I cannot give you any links or code, because I'm in a bit of a hurry. But google and the ghc docs are your friend.
Mathijs
Or
Is there a way for a JVM language or bytecode to call Haskell when
needed?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Hi all. JP Moresmau писал 20.11.2012 13:01:
You may want to have a look at my little HJVM project on Github ( https://github.com/JPMoresmau/HJVM). Promise, I'll put in on Hackage some day. Basically it provides FFI wrappers and some c code to be able to start a JVM and call Java methods, etc from Haskell.
Please take a look at http://hackage.haskell.org/package/hs-java also. It's an assembler/disassembler of Java bytecode and *.class files. Moreover, there is https://github.com/MateVM/MateVM — an (experimental) Java VM on Haskell :) So, if you are interested in haskell/java interop, maybe we could integrate our efforts. Best regards, Ilya Portnov.
-- JP Moresmau http://jpmoresmau.blogspot.com/
On Tue, Nov 20, 2012 at 7:53 AM, Mathijs Kwik <mathijs@bluescreen303.nl>wrote:
KC <kc1956@gmail.com> writes:
Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language (or generate bytecode) to access the Java class libraries when needed?
I once did a small test to get this working. It's not that hard, but needs some work. It's fine for exposing a few functions though.
Basically it's a 2-step process, eased by using a makefile or similar helper.
You have to compile your haskell code into a shared object (.so on linux, .dll on windows), which includes the haskell runtime (rts).
This library can be called from c. A small pitfall is that you first need to do a call to initialize the haskell runtime, and when you're done using it, close it. This is most easily just tied to your c/java program's main initialization functions.
Java is able to load/use these shared libraries through JNI. Of course you lose your platform-independance, so if you want your java application to work on multiple platforms / OSses, you need to build shared objects for all of them.
Last but not least: You have to export the haskell functions you want through FFI. Also, make sure they use raw data types such as CString, as that what C and java will give you and expect back.
So basically you go Haskell FFI <-> C <-> Java JNI
I'm sorry I cannot give you any links or code, because I'm in a bit of a hurry. But google and the ghc docs are your friend.
Mathijs
Or
Is there a way for a JVM language or bytecode to call Haskell when
needed?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
On Tue, Nov 20, 2012 at 11:01 AM, Ilya Portnov <portnov@iportnov.ru> wrote:
Please take a look at http://hackage.haskell.org/package/hs-java also. It's an assembler/disassembler of Java bytecode and *.class files. Moreover, there is https://github.com/MateVM/MateVM — an (experimental) Java VM on Haskell :) So, if you are interested in haskell/java interop, maybe we could integrate our efforts.
To elaborate the current state of MateVM a bit: We implement methods declared as native in Java by either IO Haskell functions or C functions. You can hook a Haskell function here in the source [1]. There're already some examples. Drawbacks are: (1) you have to mess around with the internal object layout if you want to pass values, which is JVM specific (2) it is *not* the standard way, i.e. it isn't like in JNI defined (3) we'll probably change the interface sooner or later ;) If you want to play around, you're welcome. But if you need something stable, don't use MateVM at the moment :-) it's like two man-years away from something productive usable. Bernhard [1] https://github.com/MateVM/MateVM/blob/master/Compiler/Mate/Runtime/MethodPoo...
There has been, as Antony Courtney was using Java2D for vector graphics called from Haskell in his Haven system. The FFI was GCJNI (Green Card JNI) - I'm not sure where it exists now or how much it has bit rotted. On 20 November 2012 05:36, KC <kc1956@gmail.com> wrote:
Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language (or generate bytecode) to access the Java class libraries when needed?
participants (8)
-
Bernhard Urban -
Ilya Portnov -
John Wiegley -
JP Moresmau -
KC -
Mathijs Kwik -
Stephen Tetley -
Никитин Лев