Eta works well with Haskell and Java

You’re really excited about Eta and you want to start building cool apps with it. But to build stuff without re-inventing the wheel, you’re going to want to have libraries for all the basic tasks like connecting to REST APIs, parsing JSON, and so on.

Though Eta is new, there are no shortage of libraries that you can start using

right away. One reason is because it has a smooth Java Foreign Function Interface which lets you interoperate with Java methods pretty easily. We’ve already had developers build applications interfacing with the Java SDKs for Apache Kafka, Apache Spark, Amazon Kinesis Streams, and even JDBC for uniform access to SQL databases.

Check out the on-going series on that for more information.

The other reason we don’t have a shortage of libraries is that we’ve stayed so close to Haskell syntax that the vast majority of packages on Hackage (Haskell’s package repository) compile out-of-the-box!

How we go about this will be the focus of this post.

How Does It Work?

The Hackage ecosystem works like this: a large number of packages use pure Haskell and a small subset will resort to using the C Foreign Function Interface (FFI) to be able to call C functions from Haskell. The interesting part is that the packages that use C FFI cluster near the root of the dependency graph for any practical project one works on.

In order for Eta to access this, we needed a way to deal with the C FFI calls. One way to do it would be to use the Java Native Interface to work with C, but this would make the Eta toolchain complex and platform-dependent. To stay true to Java’s selling point of platform independence, we took another route: the eta-hackage patches repository.

Etlas, the build tool for Eta, will automatically sync with this repository. Every time it notices that you’re attempting to install a package for which there exists a patch in eta-hackage repository, it will apply the patch before building the package from source. These patches can vary from being minor to rather involved and often replace the C FFI declarations and implementations with equivalent Java declarations and implementations.

For Example

Suppose you try to install the binary package, which is a serialization solution in the Haskell ecosystem. Here is a sample output from Etlas:

> etlas install binary

Resolving dependencies…

Found patch in eta-hackage for bytestring-0.10.8.2

Found patch in eta-hackage for containers-0.5.10.2

Configuring containers-0.5.10.2…

Configuring bytestring-0.10.8.2…

Building containers-0.5.10.2…

Building bytestring-0.10.8.2…

Installed bytestring-0.10.8.2

Installed containers-0.5.10.2

Configuring binary-0.8.5.1…

Building binary-0.8.5.1…

Installed binary-0.8.5.1

As seen above, Etlas will notify you when it applies a patch.

What if the patch doesn’t exist?