Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Eta interoprable with Java and/or Kotlin yet?

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?

like image 962
Thomas Cook Avatar asked Jan 17 '20 22:01

Thomas Cook


People also ask

Is kotlin interoperable with Java programming language?

Yes. Kotlin is 100% interoperable with the Java programming language and major emphasis has been placed on making sure that your existing codebase can interact properly with Kotlin.

How is Java and kotlin interoperable?

Kotlin is designed with Java interoperability in mind. Existing Java code can be called from Kotlin in a natural way, and Kotlin code can be used from Java rather smoothly as well.

What is interoperable in kotlin?

Interoperability refers to the ability to use both the Java and Kotlin languages in a single project. You can call Kotlin functions in Java as well as Java methods and variables in Kotlin code. This gives you the advantage of code reusability.

Can we write Java code in kotlin?

No you cannot do that. You can however, use java code in kotlin (if declared in a different file) and vice versa.


1 Answers

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.

like image 76
HTNW Avatar answered Sep 27 '22 17:09

HTNW