@hackage inline-java0.1
Java interop via inline Java code in Haskell modules.
Deprecated
Dependencies (10)
- base >=4.9.1 && <5
- binary >=0.7
- bytestring >=0.10
- containers >=0.5
- distributed-closure >=0.3
- inline-c >=0.5 Show all…
Dependents (3)
@hackage/jvm-streaming, @hackage/jvm-batching, @hackage/sparkle
inline-java: Call any JVM function from Haskell
The Haskell standard includes a native foreign function interface
(FFI). It can be a pain to use and in any case 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.
This is an early tech preview, not production ready.
Quasiquotation to make inline calls in Java syntax not yet implemented. But calls in Haskell syntax supported.
Example
Graphical Hello World using Java Swing:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Text (Text)
import Language.Java
newtype JOptionPane = JOptionPane (J ('Class "javax.swing.JOptionPane"))
instance Coercible JOptionPane ('Class "javax.swing.JOptionPane")
main :: IO ()
main = withJVM [] $ do
message <- reflect ("Hello World!" :: Text)
callStatic
(classOf (undefined :: JOptionPane))
"showMessageDialog"
[JObject nullComponent, JObject (upcast message)]
where
nullComponent :: J ('Class "java.awt.Component")
nullComponent = jnull
License
Copyright (c) 2015-2016 EURL Tweag.
All rights reserved.
Sparkle is free software, and may be redistributed under the terms specified in the LICENSE file.
About

Sparkle is maintained by Tweag I/O.
Have questions? Need help? Tweet at @tweagio.