This project aims to compile Haskell to the JVM, with the primary goal of seamless compatibility with GHC 7.10.3's Haskell.
Stack is used to build the code generator and the Shake builder for the RTS. The RTS build is setup so that it allows for C preprocessor directives inside of Java code.
To build everything, simply run the ./build.sh script.
$ ./build.sh
The equivalent of the program below
map :: (a -> b) -> [a] -> [b]
map f (x:xs) = f x : map f xs
map f [] = []
caf :: [Int]
caf = map (\x -> x + 1) [1..1000]
sum :: [Int] -> Int
sum (x:xs) = x + sum xs
sum _ = 0
main :: IO ()
main = do
print $ sum caf
return ()
has been successfully hand-compiled to work with the GHCVM RTS. The command
$ ./run.sh
is used to run this program.
The ghcvm executable does nothing more than generate a stub .class file for now. Once the code generator is ready, it will do something more exciting.
$ stack exec -- ghcvm --make Main.hs
All the options that are supported by GHC are currently allowed. The options will be filtered in the future.
- Overview
- NOTE: This is slightly outdated, but gives you the big picture.
- Informal FFI Specification
We aim to meet the following goals:
- Easy interop with Java libraries
- High performance lazy functional language implementation
- Seamless integration with Java IDEs
- IntelliJ
- Eclipse
- Android Studio
- Optimize for specific JVM implementations
- HotSpot VM
- Dalvik VM (for Android compatibility, a lightweight runtime)
- Support hot code reloading
- Re-use GHC's infrastructure
- Keep a several-month lag with respect to ghc's release cycle
- CLI should match that of ghc's
- A majority of the single- and multi-threaded RTS and primops have been implemented.
- A sample hand-compiled program is ready. See
sample/mapandsum
.
- Work on the code generator.
- Port the
base
library.
As you can see, this project is a large undertaking. If you would love to run your Haskell programs on the JVM and accelerate this project, join us on Gitter and we'll let you know how you can help out.
GHCVM is available under the BSD 3-Clause License, see LICENSE
for more information.
We would like to specifically thank the following groups/people:
- GHC HQ for providing a solid API to access the GHC infrastructure for the first stage of code generation (Haskell -> STG).
- Alois Cochard for his codec-jvm package that we use for code generation.
- Christopher Wells for his JAR packaging utility.
Thank you guys!