[MLton-user] Re: Compiling ML/C Program to dll / Writing a Java GUI for an ML program

Matthew Fluet matthew.fluet at gmail.com
Sun Jul 31 08:59:05 PDT 2011


On Fri, Jul 29, 2011 at 3:57 PM, Steffen J. Smolka
<steffen.smolka at in.tum.de> wrote:
> Hi,
> I have been wondering for a while now if there's a good way to make ML code
> and Java code work together.
> What I would love to do is write a program in ML and wrap it with a GUI
> written in Java/Scala.
> What I have found so far is that it's possible to make Java work with C
> (JNI/JNA) and C work with ML (with MLton's Foreign Function Interface).
> Combining this, I would hope to get Java working with ML (via an interface
> written in C).
> However, it seems that JNI/JNA only works with dynamic libraries, that is
> dlls in Windows.
> The problem is that i can't get MLton to compile my ML/C program to a
> dll. Compiling the program to an executable works just fine.
> Is it just not possible to compile ML programs to dlls with MLton or am I
> doing something wrong?
> Or is there possibly a better way to make ML code and Java code work
> together?
> I know it's possible to compile the ML programm to a standalone executable
> and simply call that executable from within Java.
> The problem is that this would limit data transfer beetween the programs to
> strings which might require lots of encoding and decoding and doesn't seem
> like a good solution.

You could certainly send binary data back and forth to the SML program
(rather than just text data).  That still requires some amount of
serialization of complex data.  But, unless you are simply passing
flat arrays of 32-bit integers (or something similar), you would still
need some amount of serialization, since Java doesn't know MLton's
native object format and MLton doesn't know Java's native object
format.

As for compiling to a DLL, there is some support for compiling a SML
program to a library.  See "http://mlton.org/LibrarySupport"; I'm not
sure that it supports compiling to a DLL, since there isn't a native
Windows port of MLton; on Windows, we use either Cygwin or MinGW.



More information about the MLton-user mailing list