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?
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.
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.
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.
No you cannot do that. You can however, use java code in kotlin (if declared in a different file) and vice versa.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With