Skip to content

Latest commit

 

History

History
 
 

jvm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

jvm: Call any JVM function from Haskell

This package enables calling any JVM function from Haskell. If you'd like to call JVM methods using Java syntax and hence get the Java compiler to scope check and type check all your foreign calls, see inline-java, which builds on top of this package.

Example

Graphical Hello World using Java Swing:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UndecidableInstances #-}

import Data.Text (Text)
import Language.Java

newtype JOptionPane = JOptionPane (J ('Class "javax.swing.JOptionPane"))
  deriving Coercible

main :: IO ()
main = withJVM [] $ do
    message <- reflect ("Hello World!" :: Text)
    callStatic
      (classOf (undefined :: JOptionPane))
      "showMessageDialog"
      nullComponent
      (upcast message)
  where
    nullComponent :: J ('Class "java.awt.Component")
    nullComponent = jnull