开发者

GUI in Java, Backend in SML?

开发者 https://www.devze.com 2023-03-24 01:52 出处:网络
I\'m a big fan of functional programming languages (namely Standard ML and its dialects), mainly because of their expressiveness which allows for very consise, clean code. I can solve many problems dr

I'm a big fan of functional programming languages (namely Standard ML and its dialects), mainly because of their expressiveness which allows for very consise, clean code. I can solve many problems dramatically faster with ML than with say Java.

However, Java is really great when it comes to programming GUIs (->SWT). I would definitely not wanna do that in a functional language.

This brings us to my actual question: Is there a good way to write a program in ML and then wrap it with a GUI written in Java?

What I have come up with so far is the following:

  • Compile the ML programm (e.g. with MLton or Poly ML) and execute the binary as an external program from Java (http://www.rgagnon.com/javadetails/java-0014.html).

    Problem: The only way the Frontend/Backend can communicate is via Strings. This might require tons of (difficult) encoding/decoding.

  • Use JNI/JNA. From what I read, this will allow you to transfer Integers, Arrays etc. I think the exte开发者_运维问答rnal programms have to be written in C/C++ for this to work. With MLton's Foreign Function Interface I can write an Interface to my functional program in C and statically link the whole thing.

    Problem: Apparantly, this only works with dynamic libraries, that is dlls in Windows. However, MLton will only let me compile the ML/C Programm to an executable. When trying to create a dll, I get a whole bunch of errors.

Does anyone have experience with this? Is there a better way to do this?

Thanks in advance! -Steffen

EDIT: I know about Scala which tries to bring concepts from functional programming to Java. I have tried it but I dont think it can compete with an actual functional programming language (in terms of expressivness)


That's not quite the exact answer but there is a functional language which is very ml-orientated for the JVM: Yeti

So if you like coding in ML than that's probably currently the closes you can get on the JVM and it integrates of course very well with all the Java APIs.


Is there a good way to write a program in ML and then wrap it with a GUI written in Java?

I don't know if this is a good way for small applications, but it is definitely a way, one that works for big IDE style stuff: Isabelle/ML vs. Isabelle/Scala/JVM. This is an application of interactive theorem proving, but plain SML programming is a trivial instance of that, in a sense.

So you can write basic Isabelle/ML code that emits some messages in the manner of the old-fashioned REPL, but the output can be interpreted by GUI components on the JVM side. Isabelle/jEdit does that routinely for pretty-printing of colored text, with a tiny little bit of rich text (sub/superscripts and bold).

Concerning explicit recoding of functional values over pipes/sockets as strings: that turns out quite simple in Isabelle/ML/Scala, due to some imitation of the way SML would represent typed values in untyped memory, but using untyped XML trees here instead of bits. The XML transfer syntax is specific to keep things simple: YXML instead of official quasi-human-readable XML. All of that fits into approx. 8000 bytes of SML source -- I am tempted to post the sources here, but better search the web for "Isabelle YXML" or "YXML PIDE".

Since Scala/JVM alone has been mentioned as standalone alternative: it definitely works, Scala is also very powerful and flexibile in imitating many programming styles (higher-order functional-object oriented), but for sophisticated symbolic applications like theorem proving, it just won't reach the purity and stability of SML. (Note that the underlying SML platform here is Poly/ML.)

0

精彩评论

暂无评论...
验证码 换一张
取 消