Haskell/Java interop via inline Java code in Haskell modules.
mboes Merge pull request #117 from matil019/fix-jvm-example
Update the example in jvm/README.md
Latest commit 4d6e51e Sep 4, 2018
Failed to load latest commit information.
.circleci Limit the amount of parallelism in circleci. Jul 11, 2018
cbits Use ByteString to carry bytecode again. Refactor C code. Aug 15, 2017
examples Import hello-java repository. Sep 14, 2017
jni jni: Bump version to 0.6.1. Jul 11, 2018
jvm-batching Disable tests which need hspec-discover for bazel. Jul 5, 2018
jvm-streaming Disable tests which need hspec-discover for bazel. Jul 5, 2018
jvm Update the example in jvm/README.md Sep 4, 2018
src/Language/Java Support building with ghc-8.4.3. Jul 11, 2018
tests Allow inline-java to marshal inner class references. Aug 30, 2017
vendor Switch to latest inline-c release. Jan 21, 2017
.gitignore Bazel build files for inline-java Dec 29, 2017
.gitmodules Switch to latest inline-c release. Jan 21, 2017
BUILD.bazel Disable tests which need hspec-discover for bazel. Jul 5, 2018
CHANGELOG.md inline-java: Bump version to 0.8.4. Jul 11, 2018
CONTRIBUTING.md Drop anchor in link to the C style guide. Aug 15, 2017
Dockerfile fixup! Add a dockerfile for tweag/inline-java. Nov 28, 2016
LICENSE copyright. Apr 20, 2016
README.md Update README.md to mention GHC plugins and to not mention Spark. May 11, 2018
Setup.hs Split off Foreign.Java into separate inline-java package. Mar 20, 2016
WORKSPACE Test bazel build in CI. Jul 5, 2018
inline-java.cabal inline-java: Bump version to 0.8.4. Jul 11, 2018
nixpkgs.nix Test bazel build in CI. Jul 5, 2018
shell-HEAD.nix Split inline-java into 3 packages: jni, jvm, inline-java. Oct 19, 2016
shell.nix circleci: Use nixos/nix image to test inline-java. Dec 12, 2017
stack.yaml jvm-batching: Update lower bound of distributed-closure. Feb 1, 2018
wercker.yml Also build benchmarks in CI (but don't run them). May 13, 2017


inline-java: Call any JVM function from Haskell


NOTE 1: you'll need GHC >= 8.0.2 to compile and use this package.

The Haskell standard includes a native foreign function interface (FFI). Using it can be a bit involved and only C support is implemented in GHC. inline-java lets you call any JVM function directly, from Haskell, without the need to write your own foreign import declarations using the FFI. In the style of inline-c for C and inline-r for calling R, inline-java lets you name any function to call inline in your code. It is implemented on top of the jni and jvm packages using a GHC Core plugin to orchestrate compilation and loading of the inlined Java snippets.


Graphical Hello World using Java Swing:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fplugin=Language.Java.Inline.Plugin #-}
module Main where

import Data.Text (Text)
import Language.Java
import Language.Java.Inline

main :: IO ()
main = withJVM [] $ do
    message <- reflect ("Hello World!" :: Text)
    [java| {
      javax.swing.JOptionPane.showMessageDialog(null, $message);
      } |]

Building it


  • the Stack build tool (version 1.2 or above);
  • either, the Nix package manager,
  • or, OpenJDK and Gradle installed from your distro.

On OS X, you'll need to install the Legacy Java SE 6 runtime when prompted, even when using Nix.

To build:

$ stack build

You can optionally get Stack to download a JDK in a local sandbox (using Nix) for good build results reproducibility. This is the recommended way to build inline-java. Alternatively, you'll need it installed through your OS distribution's package manager for the next steps (and you'll need to tell Stack how to find the JVM header files and shared libraries).

To use Nix, set the following in your ~/.stack/config.yaml (or pass --nix to all Stack commands, see the Stack manual for more):

  enable: true


The generated java output can be dumped to stderr by passing to GHC


If -ddump-to-file is in effect (as when using stack), the java code is dumped to <module>.dump-java instead.


Copyright (c) 2015-2016 EURL Tweag.

All rights reserved.

inline-java is free software, and may be redistributed under the terms specified in the LICENSE file.



inline-java is maintained by Tweag I/O.

Have questions? Need help? Tweet at @tweagio.