Haskell on JVM?
Asked Answered
Q

4

85

I'm wondering if there is some way to make Haskell run on the JVM (compiled or interpreted)?

There exists JHaskell on Sourceforge but this one seems to be empty and dead.

GHC uses LLVM as compiler backend. Would it be a good idea or possible to compile LLVM to Java bytecode? Or maybe use a different compiler backend?

Quincunx answered 31/8, 2011 at 17:38 Comment(11)
GHC FAQ: Why isn't GHC available for .NET or on the JVM?Bala
And this whole thread on haskell-cafe.Bala
Thanks for the links. So there is some mainly experimental stuff. Did you use some of them? Is there something recommendable to have a closer look at?Quincunx
I haven’t used them, but LLVM might be an interesting avenue.Bala
did tail call optimization make it into JVM 1.7?Rumelia
Tail call optimization still seems to be an open issue. That is why other functional jvm languages like Clojure need special constructs (recur).Quincunx
There is jaskell.codehaus.org for the JVM, not the real thing, but better than nothing.Snowshed
@jeha: Nah, TCO is easy. Seph does it, Erjang does it, Kawa and all the other Scheme implementations on the JVM do it. The JVM has Exceptions, which are basically the same as GOTO, which can be used to implement TCO. Or you use trampolines. Or you don't use the JVM call stack at all and just implement your own. The reason why Clojure and Scala only provide limited TCO (basically, only tail recursion is optimized) is because they want to use the JVM call stack for interoperability and performance reasons. As Rich Hickey, Clojure's designer said: Interop, speed, TCO -- Pick two.Fruit
I can't imagine it would be hard to compile Haskell to the JVM if you did not care about performance at all and only focus on what the Haskell language requires. Use trampolines as Jorg mentions. They are easy to implement. Use the simplest data structures that do the job. Don't bother optimizing. I'm sure someone could hack up a working and full implementation within a week by himself if he actually cared.Wescott
Performance or interoperability are not my concerns so far. I'd be glad to have some kind running proof of concept thing. So using trampolines sounds to be an interesting way to go. @trinithis: one week sounds quite promising - so why didn't somebody else hack this up?Quincunx
@jeha: Because performance and interop are usually the two reasons why anyone would want to implement a language on the Java platform to begin with.Fruit
M
85

You may want to investigate Frege. Quoting from that page:

"Frege is a non-strict, pure functional programming language in the spirit of Haskell."

"Frege programs are compiled to Java and run in a JVM."

Based on a brief perusal of the language specification, Frege looks to be nearly a Haskell clone. Perhaps the phrase "in the spirit of Haskell" is simpy intended to set the proper expectation.

Maura answered 16/9, 2011 at 19:49 Comment(1)
Looks like they've updated their page slightly - it now reads "Frege is a Haskell for the JVM." which is a much stronger claim IMO.Peasecod
R
29

Haskell works beautifully on the JVM. See Eta, a project that brings full GHC 7.10.3 Haskell onto the JVM with type-safe Java interop.

Reify answered 13/1, 2017 at 13:32 Comment(0)
D
12

The only language I know that is close to haskell in the JVM is CAL. CAL is heavily based on haskell but it doesn't have all haskell's features. The type system is similar to Haskell 98, and syntactic sugar like do notation is missing.

Here's a comparison of Haskell and CAL: CAL for Haskell Programmers

The eclipse plugin is very polished and useful.

Note that CAL is part of the Open Quark framework.

Doublejointed answered 2/9, 2011 at 13:11 Comment(5)
Actually I'm looking for "the real one". I can't judge about CAL. But CAL seems to have type classes btw. First impression is indeed very haskelish.Quincunx
CAL does indeed have type classes -- it's pretty close to Haskell 98 minus a fair bit of syntactic sugar.Yorgo
thanks for extra information tgdavies, I'm not a CAL programmer myselfDoublejointed
For some days I try to get the CAL for Hakell Programmers document. The link you provide does not seem to help either. Can somebody post a working link to the pdf, please?Vespine
@Ingo: this link to the user's guide should work but maybe it's not the latest one: resources.businessobjects.com/labs/cal/cal_users_guide.pdfQuincunx
B
9

There are big but surmountable impediments to GHC building to the JVM:

http://www.haskell.org/haskellwiki/GHC:FAQ#Why_isn.27t_GHC_available_for_.NET_or_on_the_JVM.3F

(Got a spare year or two to make it happen?)

Bullfinch answered 20/2, 2012 at 0:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.