Is Eta interoprable with Java and/or Kotlin yet?

288 views Asked by At

I've been learning Haskell, but during my day job I am writing Kotlin/Java.

I've come across Eta (https://eta-lang.org/), a Haskell dialect that compiles to Java byte code and runs on the JVM. On the website it states that it has:

Robust Interoperability

Eta has a strongly-typed Foreign Function Interface (FFI) that allows you to safely interoperate with Java. 

But further down the page there is a "Coming Soon" section, where the interop is listed. So my question, before I go to the hassle of setting up an environment to dev in:

Is this officially supported yet?

1

There are 1 answers

2
HTNW On BEST ANSWER

The thing that's "Coming soon" is the "bindings generator". Eta has implemented syntax for Java interop, but you need to explicitly write foreign declarations for each Java entity you want to call. E.g. as in the linked example, a class like

public class Counter {
    private int counter = 0;
    private final int max;
    public Counter(int max) { this.max = max; }
    public int postIncrement() { return max == counter ? counter : counter++; }
}

necessitates a block of foreign imports

data Counter = Counter @example.Counter deriving Class
foreign import java unsafe "@new" newCounter :: Int -> Java a Counter
foreign import java unsafe "postIncrement" postIncrement :: Java Counter Int

As you might guess, it would be preferable for this to be auto-generated. The program to do that generation is what's WIP, not the FFI itself.