GUI in Java, Backend in SML?

I am a big fan of functional programming languages ​​(namely Standard ML and its dialects), mainly because of their expressiveness, which allows you to really consult, clean the code. I can solve many problems much faster with ML than with Java.

However, Java is really great when it comes to GUI programming (-> SWT). I definitely don't want to do this in a functional language.

This brings us to my urgent question: Is there a good way to write a program in ML and then wrap it in a graphical interface written in Java?

So far I have come to the following:

  • Compile the ML program (for example, 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 Frontend / Backend can interact is to use strings. This may require subtle (complex) encoding / decoding.
  • Use JNI / JNA. From what I read, this will allow you to pass integers, arrays, etc. I think external programs should be written in C / C ++ for this to work. With MLton External Function Interface I can write an interface for my C functional program and statically link it all.
    Problem: Apparently, this only works with dynamic libraries, i.e. with dll on Windows. However, MLton will allow me to compile the ML / C program into an executable. When I try to create a dll, I get a whole bunch of errors.

Does anyone have any experience? Is there a better way to do this?
Thanks in advance! -Steffen

EDIT: I know about Scala, which is trying to convey concepts from functional programming to Java. I tried this, but I don’t think it can compete with the actual functional programming language (in terms of expressiveness)

+6
source share
2 answers

This is not an exact answer, but there is a functional language that is very ml-oriented for JVM: Yeti

So, if you like coding in ML, which is probably currently closing, you can go to the JVM, and it certainly integrates very well with all Java APIs.

+1
source

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

I don't know if this is suitable for small applications, but it is definitely a way that works for a large IDE style: Isabelle / ML vs Isabelle / Scala / JVM. This is an interactive theoretical verification application, but simple SML programming is a trivial instance of this in a way.

So, you can write the base code of Isabelle / ML, which emits some messages in the style of the old-fashioned REPL, but the output can be interpreted by the GUI components on the JVM side. Isabelle / jEdit does this for regular printing of colored text with a small amount of rich text (sub / superscript and bold).

Regarding explicitly recoding function values ​​by pipe / socket as strings: this is quite simple in Isabelle / ML / Scala, due to some imitation of how SML will represent typed values ​​in untyped memory, but using untyped XML trees instead of bits. The XML transfer syntax is specific to simplify simple use: YXML instead of official XML that is human readable. All this fits into approx. 8,000 bytes of SML source - I am tempted to publish the sources here, but it’s better to search the Internet for “Isabelle YXML” or “YXML PIDE”.

Since Scala / only the JVM is referred to as a standalone alternative: it definitely works, Scala is also very powerful and flexible in imitating many programming styles (oriented to a higher-order functional object), but for complex symbolic applications as a proof of the theorem, it just does not achieve purity and SML stability. (Note that the underlying SML platform here is Poly / ML.)

0
source

Source: https://habr.com/ru/post/893892/


All Articles